checkbox 全选与全不选
===================
function chkall(in1,in2){
var objForm = document.forms[in1];
var objLen = objForm.length;
for(var iCount = 0;iCount < objLen; iCount++){
if(in2.checked == true){
if(objForm.elements[iCount].type == "checkbox"){
objForm.elements[iCount].checked = true;
}
}else{
if(objForm.elements[iCount].type == "checkbox"){
objForm.elements[iCount].checked = false;
}
}
}
}
---------------------------------------
<td > <input type="checkbox" name="ids" value="全选" onclick="chkall('xxlb',this)"/>全部选择</td>
---------------------------------------
确认提交
===================
<html>
<head>
<script>
function out(value, num) {
if(window.confirm("您确认计算吗?")) {
var value2=value/123;
var value1=formatnumber(value2, num);
if(value1 =="NaN" || value1=="NaN.00") {
alert("您输入的不是数字");
} else {
document.all("test2").value=formatnumber(value, num);
}
}
}
function adv_format(value, num) {
var a_str = formatnumber(value, num);
var a_int = parseFloat(a_str);
if (value.toString().length > a_str.length) {
}
var b_str = value.toString().substring(a_str.length, a_str.length + 1);
var b_int = parseFloat(b_str);
if (b_int < 5) {
return a_str;
} else {
var bonus_str, bonus_int;
if (num == 0) {
bonus_int = 1;
} else {
bonus_str = "0.";
for (var i = 1; i < num; i++) {
bonus_str += "0";
}
bonus_str += "1";
bonus_int = parseFloat(bonus_str);
}
a_str = formatnumber(a_int + bonus_int, num);
}
return a_str;
}
</script>
<script>
function formatnumber(value, num) {
var a, b, c, i;
a = value.toString();
b = a.indexOf(".");
c = a.length;
if (num == 0) {
if (b != -1) {
a = a.substring(0, b);
}
} else {
if (b == -1) {
a = a + ".";
for (i = 1; i <= num; i++) {
a = a + "0";
}
} else {
a = a.substring(0, b + num + 1);
for (i = c; i <= b + num; i++) {
a = a + "0";
}
}
}
return a;
}
</script>
</head>
<body>
输入: <input type="text" name="test1" />
结果;<input type="text" name="test2" />
<input type="button" name="test" value="计算" onclick="out(document.all('test1').value,2)" />
</body>
</html>
---------------------------------------
验证钱
<html>
<head>
<script>
function out(value, num)
{
var value2=value/123;
var value1=formatnumber(value2, num);
if(value1 =="NaN" || value1=="NaN.00")
{
alert("您输入的不是数字");
}
else
{
var result=formatnumber(value, num);
if(result < 1)
result="0"+result;
document.all("test2").value=result;
}
}
function adv_format(value, num) {
var a_str = formatnumber(value, num);
var a_int = parseFloat(a_str);
if (value.toString().length > a_str.length) {
}
var b_str = value.toString().substring(a_str.length, a_str.length + 1);
var b_int = parseFloat(b_str);
if (b_int < 5) {
return a_str;
} else {
var bonus_str, bonus_int;
if (num == 0) {
bonus_int = 1;
} else {
bonus_str = "0.";
for (var i = 1; i < num; i++) {
bonus_str += "0";
}
bonus_str += "1";
bonus_int = parseFloat(bonus_str);
}
a_str = formatnumber(a_int + bonus_int, num);
}
return a_str;
}
</script>
<script>
function formatnumber(value, num) {
var a, b, c, i;
a = value.toString();
b = a.indexOf(".");
c = a.length;
if (num == 0) {
if (b != -1) {
a = a.substring(0, b);
}
} else {
if (b == -1) {
a = a + ".";
for (i = 1; i <= num; i++) {
a = a + "0";
}
} else {
a = a.substring(0, b + num + 1);
for (i = c; i <= b + num; i++) {
a = a + "0";
}
}
}
return a;
}
</script>
</head>
<body>
输入: <input type="text" name="test1" />
结果;<input type="text" name="test2" />
<input type="button" name="test" value="计算" onclick="out(document.all('test1').value,2)" />
</body>
</html>
---------------------------------------
<input type="hidden" name="uprovText" value="<c:out value="${info.ctCeProvince}"/>"/>
<SELECT name="uprov" size=1 id="uprov">
<option>请选择</option>
<option value="anhui">安徽</option>
<option value="aomen">澳门</option>
<option value="beijing" selected>北京</option>
<option value="fujian">福建</option>
<option value="gansu">甘肃</option>
<option value="guangdong">广东</option>
<option value="guangxi">广西</option>
<option value="guizhou">贵州</option>
<option value="hainan">海南</option>
function initSelectValue() {
var ctCeProvince=document.all("uprovText").value;
var ctCeEcountry=document.all("ustText").value;
document.all("ust").value=ctCeEcountry;
document.all("uprov").value=ctCeProvince;
}
<body onload="initSelectValue()">
----------------------------------------------
5 中文/英文/数字/邮件地址合法性判断
<SCRIPT LANGUAGE="javascript">
<!--
function isEnglish(name) //英文值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return false;
}
return true;
}
function isChinese(name) //中文值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return true;
}
return false;
}
function isMail(name) // E-mail值检测
{
if(! isEnglish(name))
return false;
i = name.indexOf("@");
j = name.lastIndexOf("@");
if(i == -1)
return false;
if(i != j)
return false;
if(i == name.length)
return false;
return true;
}
function isNumber(name) //数值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charAt(i) < "0" || name.charAt(i) > "9")
return false;
}
return true;
}
function CheckForm()
{
if(! isMail(form.Email.value)) {
alert("您的电子邮件不合法!");
form.Email.focus();
return false;
}
if(! isEnglish(form.name.value)) {
alert("英文名不合法!");
form.name.focus();
return false;
}
if(! isChinese(form.cnname.value)) {
alert("中文名不合法!");
form.cnname.focus();
return false;
}
if(! isNumber(form.PublicZipCode.value)) {
alert("邮政编码不合法!");
form.PublicZipCode.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
动态增加一个文本框
----------------------------------------
<HTML>
<Head>
<Script Language=JavaScript>
function insertRow(isTable){
index = isTable.rows.length;
nextRow = isTable.insertRow(index);
isText = nextRow.insertCell(0);
txtArea = nextRow.insertCell(1);
index++;
index = index.toString();
nameStr = "item"+index;
txtStr = "Item "+index;
isText.innerHTML = txtStr;
txtArea.innerHTML = "<input type=text name="+nameStr+" size=5>";
}
</Script>
</Head>
<Body>
<Form name='Form1'>
<Table id='dynTable' cellpadding=5 cellspacing=5 border=1>
<TR><TD>Item 1</TD><TD><input type="text" name="item1" size="5"></TD></TR>
<TR><TD>Item 2</TD><TD><input type="text" name="item2" size="5"></TD></TR>
<TR><TD>Item 3</TD><TD><input type="text" name="item3" size="5"></TD></TR>
</Table>
</Form>
<input type=button value="Insert row" onclick="insertRow(dynTable)" >
</Body>
</HTML>
posted on 2006-12-30 14:33
ziwolf 阅读(88)
评论(0) 编辑 收藏