我想问一下使用$()或不使用的差异$().在两种情况下,它实际上是有效的.有什么不同我真的不明白.
jQuery的
var harf = $('<p>Hello there</p>').appendTo('body');
$(harf).on('click', function(){
alert('harf');
});
Run Code Online (Sandbox Code Playgroud)
//
var harf = $('<p>Hello there</p>').appendTo('body');
harf.on('click', function(){
alert('harf');
});
Run Code Online (Sandbox Code Playgroud)
第一个是完全没用的.在jQuery对象中嵌入jQuery对象没有意义.
请注意,你可以链接调用,你真的不需要那个harf变量:
$('<p>Hello there</p>').on('click', function(){
alert('harf');
}).appendTo('body');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |