Example: why not use javascript in the industry

Source: Internet
Author: User

Many people have used Javascript like this.
Copy codeThe Code is as follows:
<A href = "#" onclick = "al ()"> Save </a>

The above code is very convenient to use and is supported by all browsers.

Although I have read some books long ago, such as html, css, and js, which are easier to maintain, I write this frequently in the aspect of pictures, but I found it when debugging with Firefox today, do not write it in the industry, because it is not safe, because the firebug of Firefox can easily invalidate the code!

Let's take a look at why:
Copy codeThe Code is as follows:
<Html>
<Head>
<Script>
Function al ()
{
Alert ("good ");
}
</Script>
</Head>
<Body>
<A href = "#" onclick = "al ()"> Save </a>
</Body>
</Html>

The above code is to click the tag to bring up the dialog box

Effect
 

However, if I find the tag in Firefox and remove the js Code, the dialog box will not pop up when I click the tag, as shown in figure
 

Therefore, if you click the event to determine whether the user input data is valid, you cannot determine

I am working on asp.net and found this problem today. Because of the asp.net Server Control, there are two click events, one at the front end and one at the backend, I use the front-end click event to judge the user input data, if it is legal, the background event is called and the result is debugged by Firefox. As described above, the background method is directly called even if the data is invalid. Maybe I am not a technology, but I'm glad to find this problem. I 'd like to share this article, haha.

Solution:

Give a tag id, as shown below.
Copy codeThe Code is as follows:
<A id = "a1" href = "#"> Save </a>
<Script>
Document. getElementById ("a1"). onclick = function (){}
</Script>

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.