Many people have used Javascript like this
The above code is very convenient to use and is supported by all browsers
Although I am very early I have read some books, saying that it is easier to maintain if HTML, CSS, and JS are separated. However, I am greedy for convenience, so I often write like this. However, when I used Firefox to debug today, I found that it is better not to write inline, because it is very unsafe. , because using Firefox’s firebug can easily invalidate the code!
Let’s take a look at why:
< ;html>
<script> <br>function al() <br>{ <br>alert("good"); <br>} <br></script>
Save
The above code is to click the label to pop up the dialog box
The effect is as shown below:
But if I If you find the a tag in Firefox and remove the js code inside, the dialog box will not pop up when you click the a tag, as shown below
So if your click event is It is impossible to judge whether the data entered by the user is legal.
I work in asp.net and I discovered this problem today because the asp.net server control has two click events, one in the front desk and one in the front desk. In the background, I used the click event in the foreground to judge the user's input data. If it was legal, I called the background event. As a result, I used Firefox to debug and discovered the phenomenon described above. Even if the data is illegal, the background method is called directly. Maybe I am not doing this. What kind of technology, but I am happy that I discovered this problem, and hereby post an article to share it, haha
Solution:
Give a tag an id, as shown below
Save <script> <br>document.getElementById("a1").onclick=function(){} <br></script>