我有一个javascript函数
<script>
$(document).ready(function(){
$('.paper_img').click(function(){
console.log("hello")
return false;
});
});
</script>
如何访问触发此功能的元素? 谢谢 卡尔
答案 0 :(得分:0)
this
关键字可让您访问调用者。
答案 1 :(得分:0)
$(document).ready(function() {
$('.paper_img').click(function() {
$('div').html($(this).attr('id') + ' was clicked!');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="button_1" class="paper_img">Click me!</button>
<button id="button_2" class="paper_img">Click me!</button>
<button id="button_3" class="paper_img">Click me!</button>
<button id="button_4" class="paper_img">Click me!</button>
<div></div>