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>