148 lines
4.3 KiB
HTML
148 lines
4.3 KiB
HTML
|
||
<div id="sina_keyword_ad_area2" class="articalContent ">
|
||
<div>
|
||
<div>附加:js验证radio是否选择</DIV>
|
||
<div><br /></DIV>
|
||
<div><script
|
||
language="javascript"></DIV>
|
||
<div>function checkform(obj)</DIV>
|
||
<div>{</DIV>
|
||
<div>for(i=0;i<obj.oo.length;i++)</DIV>
|
||
<div> <wbr> <wbr> <wbr>
|
||
<wbr> <wbr> if(obj.oo[i].checked==true)
|
||
return true;</DIV>
|
||
<div><br /></DIV>
|
||
<div>alert("请选择")</DIV>
|
||
<div>return false; <wbr> <wbr>
|
||
<wbr> <wbr></DIV>
|
||
<div><br /></DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
<div><form id="form1" name="form1" method="post"
|
||
action="" <wbr> onsubmit="return
|
||
checkform(this)"></DIV>
|
||
<div> <wbr> <wbr> <input
|
||
type="radio" name="oo" value="radiobutton" /></DIV>
|
||
<div> <wbr> <wbr> <input
|
||
type="radio" name="oo" value="radiobutton" /></DIV>
|
||
<div> <wbr> <wbr> <input
|
||
type="submit" name="Submit" value="提交" /></DIV>
|
||
<div></form></DIV>
|
||
<div><br /></DIV>
|
||
<div>1. 长度限制</DIV>
|
||
<div><script></DIV>
|
||
<div>function test() <wbr></DIV>
|
||
<div>{</DIV>
|
||
<div>if(document.a.b.value.length>50)</DIV>
|
||
<div>{</DIV>
|
||
<div>alert("不能超过50个字符!");</DIV>
|
||
<div>document.a.b.focus();</DIV>
|
||
<div>return false;</DIV>
|
||
<div>}</DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
<div><form name=a onsubmit="return
|
||
test()"></DIV>
|
||
<div><textarea name="b" cols="40" wrap="VIRTUAL"
|
||
rows="6"></textarea></DIV>
|
||
<div><input type="submit" name="Submit"
|
||
value="check"></DIV>
|
||
<div></form> <wbr></DIV>
|
||
<div><br /></DIV>
|
||
<div>2. 只能是汉字 <wbr></DIV>
|
||
<div><input
|
||
onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')"></DIV>
|
||
<div><br /></DIV>
|
||
<div>3." 只能是英文</DIV>
|
||
<div><script
|
||
language=javascript></DIV>
|
||
<div>function onlyEng()</DIV>
|
||
<div>{</DIV>
|
||
<div>
|
||
if(!(event.keyCode>=65&&event.keyCode<=90))</DIV>
|
||
<div>event.returnvalue=false;</DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
<div><br /></DIV>
|
||
<div><input
|
||
onkeydown="onlyEng();"></DIV>
|
||
<div><br /></DIV>
|
||
<div>4. 只能是数字</DIV>
|
||
<div><script
|
||
language=javascript></DIV>
|
||
<div>function onlyNum()</DIV>
|
||
<div>{</DIV>
|
||
<div>
|
||
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))</DIV>
|
||
<div>//考虑小键盘上的数字键</DIV>
|
||
<div>event.returnvalue=false;</DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
<div><br /></DIV>
|
||
<div><input
|
||
onkeydown="onlyNum();"></DIV>
|
||
<div><br /></DIV>
|
||
<div>5. 只能是英文字符和数字</DIV>
|
||
<div><input
|
||
onkeyup="value="/oblog/value.replace(/[\W]/g,"'')
|
||
"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"></DIV>
|
||
<div><br /></DIV>
|
||
<div>6. 验证油箱格式</DIV>
|
||
<div><SCRIPT LANGUAGE=javascript
|
||
RUNAT=Server></DIV>
|
||
<div>function isEmail(strEmail) {</DIV>
|
||
<div>if
|
||
(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)
|
||
!= -1)</DIV>
|
||
<div>return true;</DIV>
|
||
<div>else</DIV>
|
||
<div>alert("oh");</DIV>
|
||
<div>}</DIV>
|
||
<div></SCRIPT></DIV>
|
||
<div><input type=text
|
||
onblur=isEmail(this.value)></DIV>
|
||
<div><br /></DIV>
|
||
<div>7. 屏蔽关键字(这里屏蔽***和****)</DIV>
|
||
<div><script
|
||
language="javascript1.2"></DIV>
|
||
<div>function test() {</DIV>
|
||
<div>if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf
|
||
("****") == 0)){</DIV>
|
||
<div>alert("");</DIV>
|
||
<div>a.b.focus();</DIV>
|
||
<div>return false;}</DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
<div><form name=a onsubmit="return
|
||
test()"></DIV>
|
||
<div><input type=text name=b></DIV>
|
||
<div><input type="submit" name="Submit"
|
||
value="check"></DIV>
|
||
<div></form></DIV>
|
||
<div><br /></DIV>
|
||
<div>8. 两次输入密码是否相同</DIV>
|
||
<div><FORM METHOD=POST
|
||
ACTION=""></DIV>
|
||
<div><input type="password"
|
||
id="input1"></DIV>
|
||
<div><input type="password"
|
||
id="input2"></DIV>
|
||
<div><input type="button" value="test"
|
||
onclick="check()"></DIV>
|
||
<div></FORM></DIV>
|
||
<div><script></DIV>
|
||
<div>function check()</DIV>
|
||
<div>{ <wbr></DIV>
|
||
<div>with(document.all){</DIV>
|
||
<div>if(input1.value!=input2.value)</DIV>
|
||
<div>{</DIV>
|
||
<div>alert("false")</DIV>
|
||
<div>input1.value = "";</DIV>
|
||
<div>input2.value = "";</DIV>
|
||
<div>}</DIV>
|
||
<div>else document.forms[0].submit();</DIV>
|
||
<div>}</DIV>
|
||
<div>}</DIV>
|
||
<div></script></DIV>
|
||
</DIV>
|
||
</div>
|