ClassYuan's blog. http://www.classyuan.com/. Here are some examples:
1. When loading an event with an HTML element, the event will be executed at the same time as it is loading.
Error code:
I ignored the Bind method in this code. The explanation of Api is bind (type,[data],fn)
I mistakenly regarded fn as a simple function. As a result, this code will execute the fn once when loading..
This is an oversight in writing format. I hope someone who knows the reason can give me some advice.
2 The problem of variable scope. (It seems that this is not a problem with jquery. It is the difference between js and .net..)
function text() {
2 for (var i = 0; i < 3; i ) {
3 $("
Delete ").attr({ id: "hr_" i, href: "javascript:;" }).addClass("btnCss").bind("click", function() { tes(i) } ).appendTo(".div_list");
4 }
5 }
6 function tes(id) {
7 alert(id);
8 }
This function. I want it to alert the corresponding id. The result is that the answer is very agreeable. It is a function with 3
If you can’t understand the principle of writing this way, it doesn’t matter. Remember this form first, and you will encounter similar problems in the future. The problem is written according to this idea, that is, a layer of (function() { xxx })();
Speaking of the original painting, it is actually very simple. When passing the function, i, as a basic type variable, is passed by value. , which means that the current value of i will be copied to this function, so every time this anonymous function is called, i is independent of each other and will not be affected by the outer for
When a does not give the href attribute, href defaults to the address of the current page, so you will jump after clicking. Therefore, there are several popular processing methods on the Internet:
1.
2.
3.