目录:
------------------------------------------------------------
1 下拉框转向对应网址
2 某控件获得焦点
3 控制控件样式
4 利用JS切换Form的Target。
5 window的用法
6 控制DropDowList
7 所有控件清空
8 从框架返回登陆首页
9 框架A执行B里的事件
1 下拉框转向对应网址
<SELECT onchange="javascript:window.open(this.options[this.selectedIndex].value)">
<OPTION selected></OPTION>
<OPTION value="http://www.sina.com.cn">新浪</OPTION>
</SELECT></FONT>
2 某控件获得焦点
<SCRIPT language=javascript> document.Form1.USER.focus();</SCRIPT>
3 控制控件样式
<script language="javascript">
//设置控件显示形式
function setVisible (element,key)
{
document.getElementById(element).style.display=key;
}
</script>
key可以为"block","none"和""等
4 利用JS切换Form的Target。使之极为方便
function set2()
{
document.form1.target ="_self";
}
function setback()
{
document.form1.target ="main";
}
在VB文件中:
Button2.Attributes.Add("onclick", "return set2();")
5 window的用法
window.close()//关闭
window.alert()//警告框
window.confirm()//确定框
window.opener.location=''//父页重定位
window.opener.Reload()//父页刷新
6 控制DropDowList:
function Add1()
{
//给DropDownList1增加一个选项
var oOption = document.createElement("OPTION");
document.getElementById("DropDownList1").options.add(oOption);
oOption.innerText = "ABCD";
oOption.value = "1234";
}
function Delete1()
{
if(document.all["DropDownList1"].options.length>0)
{
//删除DropDownList1一个选项
document.all["DropDownList1"].options.remove(0);
//选中一项
document.all["DropDownList1"].selectedIndex = 0;
}
}
应该是父页面,给上面的document前加上parent.就可以了~
7 所有控件清空:
function Reset()
{
var i
var intLength = Form1.elements.length
for (i = 0; i < intLength; i ++)
{
var type = Form1.elements[i].type;
var tagName = Form1.elements[i].tagName;
var Name = Form1.elements[i].name;
if (tagName == "INPUT" && type == "text")
{
Form1.elements[i].value = "";
}
if (tagName == "SELECT")
{
Form1.elements[i].selectedIndex = 0;
}
if (tagName == "TEXTAREA")
{
Form1.elements[i].value = "";
}
if (type == "hidden" && Name != "__VIEWSTATE")
{
Form1.elements[i].value = "";
}
}
}
8 从框架返回登陆首页
Response.Write("<script language=javascript>")
Response.Write("window.parent.location.href='../login.aspx'")
Response.Write("</script>")
9 框架A执行B里的事件.
a中
button onclick="parent.window.Frames['bFrameID'].window.document.getElementById('bBtn').click();"