国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - Problems with calling functions in JQuery click events
曾經蠟筆沒有小新
曾經蠟筆沒有小新 2017-05-19 10:18:04
0
3
537

Figure 2 calls the function in Figure 1, and the output is Undefined, but in Figure 2, the same code is used in the JQ click event and the output result is. Then I declared a variable obj in the test function to obtain all objects with the attribute name=component_checkbox[]. At this time, there is output when calling this function in the JQ click event. My question is why the test() in Figure 2 does not output the result but is undefined when the code in Figure 1 is used?

曾經蠟筆沒有小新
曾經蠟筆沒有小新

reply all(3)
我想大聲告訴你

Replace picture 2 with this:

// test()  要指定this 為被點擊的元素 
test.call(this);  // 利用call方法 

MDN - Function.prototype.call

習慣沉默

Because the scope of this is different, this in the click closure refers to the checkbox you selected, and in the test function, this refers to the window or other object

巴扎黑

In Figure 1, $(this) has no pointing value

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template