JavaScript uses style name classname to get corresponding objects

Source: Internet
Author: User
The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<style type= "Text/css" >
* Reset Style * *
* {margin:0; padding:0;}
. input_ocurrent {padding:2px; border:1px solid #DDD; background: #FFF;}
. Input_ocurrent:hover,. input_ocurrent:focus {border:1px solid #444; background: #DDD;}
. input_current {padding:2px; border:1px solid #444; background: #DDD;}
</style>
<script type= "Text/javascript" >
function Displayinput (elementid) {
Get a collection of span labels
var spanzone = document.getElementsByTagName ("span");
Gets the number of span tags (which are repeated in a for)
var spanlength=spanzone.length;
var inputzone;//the span that you need
for (Var i=0;i<spanlength;i++)
{
To get the one you're looking for.
if (Spanzone[i].classname==elementid)
{
Inputzone=spanzone[i];
}
}
Get the input tag collection for the span label
var inputtx=inputzone.getelementsbytagname ("input");
Number of sets of input in span (separate write to prevent repeat calculation)
var inputlength=inputtx.length;
for (var i=0;i <inputLength; i++) {
Dynamically adding onmouseover events: When the mouse is moved to the input to determine if this Inpu class is input_ocurrent if yes, add onmouseover event to remove the same
if (Inputtx[i].classname = = "Input_ocurrent") {
Inputtx[i].onmouseover=function () {
This.classname = "Input_current";
}
Inputtx[i].onmouseout=function () {
This.classname = "Input_ocurrent";
}
}
}
}
Window.onload =function () {
Displayinput ("Input_zone");
}
</script>
<body>
<span class= "Input_zone" >
<input class= "input_ocurrent" name= "type=" text "size=" "/>"
<input class= "input_ocurrent" name= "type=" text "size=" "/>"
</span>
</body>

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.