JS and a href className JS compile the sequence and run the sequence string or variable embedded in brackets instead of the point number represents the attribute, hrefclassname

Source: Internet
Author: User

JS and a href className JS compile the sequence and run the sequence string or variable embedded in brackets instead of the point number represents the attribute, hrefclassname
JS and a href

Note The End Of The semicolon in href and close the quotation marks.

<A href = "javascript:;"> Empty link </a> <a href = "javascript: alert ('A');"> pop-up </a>


Generally, you can leave the code empty. If it is empty, you can also use the pound sign '#', but it is not very good.


ClassName


<Style> # div1 {width: 100px; height: 100px; border: 1px solid black ;}. box {background: red ;}</style> <script> function toRed () {var oDiv = document. getElementById ('div1 '); oDiv.ClassName= 'Box'; // do not write it as a class} </script> 

1. getelementbyId is connected to the id, but there is no method connected to the class.

GetElementById () Returns a reference to the first object with the specified id.
GetElementsByName () Returns a set of objects with the specified name.
GetElementsByTagName () Returns an object set with the specified tag name.

Use JS to create a className index style according to/. You need to add a second-level Attribute '. classname' after getelement '.

After the tag is added, the tag of the specified id is not only from the style of the 'Pound 'index for the id, but also from the 'dot' index for the class style.


2. changes caused by getelement. className = 'box'; // The above example is the same for oDiv.

If the <div> label already contains the class = xxx attribute, the class = xxx attribute will be changed to class = box when the event action leads to the function.

If <div> no class = xxx, it will be created along with the script execution.

Recall that if <div> unspecified style = XXX, getelement. style. backgroud will also be automatically created.

Getelement. + style/class/type/href/value and so on. It is convenient and convenient to add a new style.

This is just a method.

-Getelement ['value'] is enclosed in brackets, which is the same as the out attribute of. (DOT). Generally, [''] is not used in special cases.

If [''] refers to a variable, assume a = 'width ', then ['a'] becomes [''width''], which does not conform to the concept of getelement ['properties.

At this time, the solution can be [a] without quotation marks!

-All. values can be replaced [''].

ODiv. className = 'box'; // The following is equivalent.

ODiv ['classname'] = 'box ';

You can also use multiple layers. oDiv ['style'] ['width'] = '40px'

-When do I need to use ['']? Function parameters can be uploaded to values. Sometimes, if you want to upload an attribute name to indicate an attribute, you need to use [''].




JavaScript embedded html running sequence:

-Execute the event action and execute the JS function pointing to it. The function modifies the tag of the specified id.

JavaScript embedded html code writing sequence:

-Think about the effect of the change, mark the id/class to the specified effect tag, use. Or # create {style}, call the ID to write the logic for changing css, and trigger the change using the event function.

Related Article

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.