1.只能输入英文和数字
<asp:TextBox ID="UserName" class="form-leth200" runat="server" onkeyup="value=value.replace(/[\W]/g,'') "
onbeforepaste="clipboardData.setData('UserName',clipboardData.getData('UserName').replace(/[^\d]/g,''))">
</asp:TextBox>
2.判断文本框输入字符,及时提示
前台脚本:
<script language="JavaScript" type="text/JavaScript">
<!--
var testleng=200;//允许多少字符串填入
function GC_UpdateCharCount()
{
var desc_el = document.getElementById('txtCause');
var remainingchars_el = document.getElementById('remainingchars');
var num_remaining = testleng - desc_el.value.length;
if (num_remaining >= 0)
{
remainingchars_el.innerHTML = num_remaining;
}
else
{
remainingchars_el.innerHTML = "<font color=red>-" + (-num_remaining + '') + "</font>";
}
}
-->
</script>
<TEXTAREA runat="server" id=txtCause onkeydown=GC_UpdateCharCount() onkeyup=GC_UpdateCharCount() onblur="isOver(this);" Width="273px" Height="89px" name=desc rows=6 cols=50></TEXTAREA> 还有: <SPAN id=remainingchars></SPAN><NOSCRIPT>200字</NOSCRIPT>字
3.执行前台页的脚本
前台脚本:
<script language ="javascript" type="text/javascript">
function doFailure(sErrMessage)
{
alert(sErrMessage);
}
</script>
后面代码:
if (!string.IsNullOrEmpty(Request["errMessage"]))
{
string errMsg = Request["errMessage"];
Page.RegisterStartupScript("doFilure", "<script language=javascript> doFailure(\"" + errMsg + "\")</script>");
}
4.向包含的iframe页面传值(Content.aspx为iframe页面)
Page.RegisterStartupScript("", "<script>document.getElementById('bb').src='Content.aspx?modelid=" + code + "&infoid=" + infoid + "&type=" + type + "&KeyWords=" + key + "&name=" + name + "&more=" + more + "'</script>");
5.iframe同级刷新(Content.aspx为iframe页面)
前台:
function linkiframe(src){
// debugger;
iframe = document.getElementById("bb");
if(iframe){
iframe.src = src;
}else{
alert("失败!");
}
}
控件后台:
row1["LINK"] = "<a href='javascript:return false;' onclick=\"linkiframe('Content.aspx?modelid=ZX_ZhiNan&KeyWords=申办流程')\">申办流程</a>";
6.从a页面打开b页,并把b页面的值传给a页面
a页面:
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<input name="Submit" type="button" onClick="MM_openBrWindow('/Default17.aspx','','scrollbars=yes,width=300,height=400')" value="打开新窗口">
b页面:
<script>
function returnText() {
window.opener.form1.text.value=form1.text.value;
window.close();
}
</script>
<input name="text" type="text" id="text" value="请输入你的内容">
<br>
<input type="button" name="Submit" value="关 闭" onClick="returnText()">