js页面处理常见问题
2.js获取html页面传参
function GetQueryString(name) {
alert(GetQueryString("参数名3"));
//string scriptmsg = "javascript:window.parent.GetJson();";
//string scriptmsg = "window.parent.frames['frmright'].GetJson()";
//string scriptmsg =top.location.href = '/Login.aspx'
string scriptmsg ="window.parent.frames['frmmain'].frames['frmright'].GetJson()";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "js", scriptmsg, true);
前台页面要有GetJson()这个方法;
4.父级页面按键
var d3 = $(top.window.frames["frmmain"].document).find("#btnSearh");
d3.click();
top.window.frames["frmright"].document.location.reload(true);
top.window.frames["frmright"].__doPostBack('AspNetPager1', '')
给select下拉菜单添加js事件
下面是获得value的值:
<select id="se" onchange="alert(this.options[this.selectedIndex].value)">
<option value='1'>A</option>
<option value='2'>B</option>
<option value='3'>C</option>
<option value='4'>D</option>
<option value='5'>E</option>
</select>
下面是获得选项内容的值:
<select id="se" onchange="alert(this.options[this.selectedIndex].innerText)">
<option value='1'>A</option>
<option value='2'>B</option>
<option value='3'>C</option>
<option value='4'>D</option>
<option value='5'>E</option>
</select>
JS获取radio被选中的值
function getRadioValue(objName)
{
var objs = document.getElementsByName(objName);
for(var i=0; i<objs.length; i++)
{
if(objs[i].tagName.toLowerCase()=='input' && objs[i].checked) return
objs[i].value;
}
return null;
}
JSradio设置选中
$("input[name=radSex2][value=" + sex + "]").attr("checked", true);
var sex = $("input[name='radSex2']:checked").val();
checkbox全选,全不选
function selectAll(obj) {
var allInput = document.getElementsByTagName("input");
//alert(allInput.length);
var loopTime = allInput.length;
for (i = 0; i < loopTime; i++) {
//alert(allInput[i].type);
if (allInput[i].type == "checkbox") {
allInput[i].checked = obj.checked;
}
}
}
//提取查找字符串前面所有的字符
function getfront(mainstr,searchstr){
foundoffset=mainstr.indexof(searchstr);
if(foundoffset==-1){
return null;
}
return mainstr.substring(0,foundoffset);
}
//提取查找字符串后面的所有字符
function getend(mainstr,searchstr){
foundoffset=mainstr.indexof(searchstr);
if(foundoffset==-1){
return null;
}
return mainstr.substring(foundoffset+searchstr.length,mainstr.length);
}