A JS gadget. Several attribute additions cannot exceed a specific value. _javascript Tips

Source: Internet
Author: User
The most famous example is kingdoms and Tai ge to assign attribute values to the new generals role.
Next, use JavaScript to do such a function, by the way the link in the page underline to hide out.
Let's see what better ideas to optimize, everyone.
Here's the code:
The first is test.html:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<script language= "JavaScript" src= "Util.js" type= "Text/javascript" ></script>
<link rel= "stylesheet" href= "Link.css" type= "Text/css" >
</HEAD>
<body >
<form name= "Register1form" method= "POST" >
<table>
<tr>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "font1" ><div align= "right" >username</ Div></td>
&LT;TD height= bordercolor= "#FFFFFF" bgcolor= "#D0E8FF" class= "Font1" > <div align= "Center" >
<input name= "username" type= "text" size= "" Maxlength= "Ten" value= "1" >
</div></td>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "Bg2" >
<div align= "center" ><font color= "#FF0000" ><font color= "#FF0000" ><font face= "black Body" ><a href= "" Onclick= "Javascript:add (Register1form); return false;" class= "A" >+</a></font></font></ font></div& gt;</td>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "Bg2" >
<div align= "center" ><font color= "#FF0000" ><font color= "#FF0000" ><font face= "black Body" ><a href= "" Onclick= "javascript:subtration (Register1form); return false;" class= "A" >-</a></font></font ></font></div& gt;</td>
</tr>
<tr>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "font1" ><div align= "right" >meili</div ></td>
&LT;TD height= bordercolor= "#FFFFFF" bgcolor= "#D0E8FF" class= "Font1" > <div align= "Center" >
<input name= "Meili" type= "text" size= "" Maxlength= "Ten" value= "1" >
</div></td>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "Bg2" >
<div align= "center" ><font color= "#FF0000" ><font color= "#FF0000" ><font face= "black Body" ><a href= "" Onclick= "JAVASCRIPT:ADD2 (Register1form); return false;" class= "A" >+</a></font></font></ font></div& gt;</td>
&LT;TD height= "bordercolor=" "#FFFFFF" bgcolor= "#D0E8FF" class= "Bg2" >
<div align= "center" ><font color= "#FF0000" ><font color= "#FF0000" ><font face= "black Body" ><a href= "" Onclick= "Javascript:subtration2 (Register1form); return false;" class= "A" >-</a></font></font ></font></div& gt;</td>
</tr>
</table>
</form>
</body>

There are also LINK.CSS:
Copy Code code as follows:

. A
Text-transform:none;
Text-decoration:none;
}
. a:hover {
Text-decoration:underline
}

The last is util.js (this code is longer):
Copy Code code as follows:

var Flag=false;
function Add (formname) {
if (Formname.username.value = = "") {
Alert ("Please enter a positive integer");
Formname.username.focus ();
return false;
}
Flag = Checkscope (FormName);
if (Flag==false) {
return false;
}
if (parseint (formname.username.value) >0) {
Formname.username.value =parseint (formname.username.value) +1;
if (parseint (formname.username.value) +parseint (formname.meili.value) >10) {
Alert ("The sum of the integers entered must not be greater than 10");
Formname.username.value =10-parseint (Formname.meili.value);
return false;
}else
return true;
}else{
Alert ("The entered integer must be greater than 0");
Formname.username.value = 1;
return false;
}
}
function Subtration (formname) {
if (Formname.username.value = = "") {
Alert ("Please enter a positive integer");
Formname.username.focus ();
return false;
}
Flag = Checkscope (FormName);
if (Flag==false) {
return false;
}
if (parseint (formname.username.value) >1) {
Formname.username.value =parseint (Formname.username.value)-1;
if (parseint (formname.username.value) +parseint (formname.meili.value) >10) {
Alert ("The sum of the integers entered must not be greater than 10");
Formname.username.value =10-parseint (Formname.meili.value);
return false;
}else
return true;
}else if (parseint (formname.username.value) ==1) {
Alert ("is already the minimum value, can not be reduced again");
return false;
}else{
Alert ("The entered integer must be greater than 1");
Formname.username.value = 1;
return false;
}
}
function Add2 (formname) {
if (Formname.meili.value = = "") {
Alert ("Please enter a positive integer");
Formname.meili.focus ();
return false;
}
Flag = Checkscope (FormName);
if (Flag==false) {
return false;
}
if (parseint (formname.meili.value) >0) {
Formname.meili.value =parseint (formname.meili.value) +1;
if (parseint (formname.username.value) +parseint (formname.meili.value) >10) {
Alert ("The sum of the integers entered must not be greater than 10");
Formname.meili.value =10-parseint (Formname.username.value);
return false;
}else
return true;
}else{
Alert ("The entered integer must be greater than 0");
formname.meili.value=1;
return false;
}
}
function Subtration2 (formname) {
if (Formname.meili.value = = "") {
Alert ("Please enter a positive integer");
Formname.meili.focus ();
return false;
}
Flag = Checkscope (FormName);
if (Flag==false) {
return false;
}
if (parseint (formname.meili.value) >1) {
Formname.meili.value =parseint (Formname.meili.value)-1;
if (parseint (formname.username.value) +parseint (formname.meili.value) >10) {
Alert ("The sum of the integers entered must not be greater than 10");
Formname.meili.value =10-parseint (Formname.username.value);
return false;
}else
return true;
}else if (parseint (formname.meili.value) ==1) {
Alert ("is already the minimum value, can not be reduced again");
return false;
}else{
Alert ("The entered integer must be greater than 1");
formname.meili.value=1;
return false;
}
}
function Checkscope (formname) {
if ((parseint (formname.username.value) >9) | | (parseint (Formname.username.value) <1)) {
Alert ("Username input number exceeds the allowable range 1-9");
formname.username.value=1;
Formname.username.focus ();
return false;
}
if ((parseint (formname.meili.value) >9) | | (parseint (Formname.meili.value) <1)) {
Alert ("Meili input number exceeds the allowable range 1-9");
formname.meili.value=1;
Formname.meili.focus ();
return false;
}
return true;
}

Three files in the same folder, and then try the effect, I certainly did not lie to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.