在这里让我们一起学习,一起提高!
<html>
<head>
<title>判断多选,单选是否选中</title>
<script>
function checkRadioOrCheckbox(formObject){
var fObject=formObject;
var checkboxObject=document.getElementsByName("ckname");
var radioObject=document.getElementsByName("radioname");
var cknum=0;
var radionum=0;
for(var j=0;j<checkboxObject.length;j++){
if(checkboxObject[j].checked){
cknum=cknum+1;
}
}
if(cknum==0){
alert("checkbox没选");
return false;
}else if(cknum>3){//超过3个checkbox checked
alert("最多选3个");
return false;
}
for(var j=0;j<radioObject.length;j++){
if(radioObject[j].checked){
radionum=radionum+1;
}
}
if(radionum==0){
alert("radio没选");
return false;
}
}
</script>
</head>
<body>
<form method="post" action="" onsubmit="return checkRadioOrCheckbox(this);">
<div>
<div>checkbox</div>
<input type="checkbox" name="ckname" value="0">
<input type="checkbox" name="ckname" value="1">
<input type="checkbox" name="ckname" value="2">
<input type="checkbox" name="ckname" value="3">
<input type="checkbox" name="ckname" value="4">
<input type="checkbox" name="ckname" value="5">
</div>
<div>
<div>radio type</div>
<input type="radio" name="radioname" value="0">
<input type="radio" name="radioname" value="1">
<input type="radio" name="radioname" value="2">
<input type="radio" name="radioname" value="3">
<input type="radio" name="radioname" value="4">
</div>
<input type="submit" name="submit" value="测试checkbox or radio checked">
</form>
</body>
</html>
表单输入限制(小结)
只能输入汉字:
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
只能输入数字:
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能输入英文和数字:
<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能输入汉字:
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
只能输入数字:
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
只能输入英文和数字:
<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
1、父子窗口
打开一个子窗口:
<a href='#' onClick='JavaScript:window.open("sub_win_name.html")'>open</a>
打开即最大化:
<body onLoad="window.resizeTo(screen.width, screen.height);window.moveTo(0, 0);">
得到父窗口的控件:
window.opener.document.forms[0].txt1.value;
得到父窗口全局javascript变量:
window.opener.var
刷新父页面:
self.opener.location='url of super page'
打开一个子窗口:
<a href='#' onClick='JavaScript:window.open("sub_win_name.html")'>open</a>
打开即最大化:
<body onLoad="window.resizeTo(screen.width, screen.height);window.moveTo(0, 0);">
得到父窗口的控件:
window.opener.document.forms[0].txt1.value;
得到父窗口全局javascript变量:
window.opener.var
刷新父页面:
self.opener.location='url of super page'
1.document.write(""); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或&#118alue)
6.一个小写转大写的&#106s: document.getElementById("output").&#118alue = document.getElementById("input").&#118alue.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用+号.
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或&#118alue)
6.一个小写转大写的&#106s: document.getElementById("output").&#118alue = document.getElementById("input").&#118alue.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用+号.
这个一般用于文章查看的页面,针对新闻性质的网站,此外这个算法是直接分析网页中所有图片的,因此如果你的版面设计中有比指定宽度大的图片是不能用这个函数的(或者用id区分开)