我有一个由javacript创建的链接
import com.sun.javafx.scene.control.skin.TextFieldSkinAndroid;
(我有库jquery)
<a href="javascript:void(0)" class="view-more" start="15">View more</a>
答案 0 :(得分:2)
$('.view-more').click(function() {
console.log($(this).attr('start'));
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" class="view-more" start="15">View more</a>
&#13;
)
。#
href="#"
醇>
如果要动态创建链接,则应使用
之类的事件委派
$("body").append('<a href="#" class="view-more" start="15">View more</a>')
$(document).on('click','.view-more',function() {
console.log($(this).attr('start'));
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
.on()
添加动态添加的元素