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>