我有我的脚本,我想从图像attr获取数据并将其传递给我的函数
<script>
function getsomedata(this){
var comment_id=$(this).attr('data-commentId');
var comment_user=$(this).attr('data-commentUser');
var who_like=$(this).attr('data-whoLike');
var like_num_in_comment=$(this).attr('data-likeNuminComment');
//do something
})
}
echo '<img onclick="getsomedata(this)" class="c_like_icon" title="'.$reply_id.'" data-commentId="'.$reply_id.'" data-commentUser="'.$reply_array['comment_user'].'" data-whoLike="'.$username.'" data-likeNuminComment="'.getcommentdetail($reply_id,'like_num').'" src="img/thumb_icon.png" height="18" width="18">';
答案 0 :(得分:0)
试试这个:
$(".c_like_icon").click(function(e) {
getsomedata($(this));
});
function getsomedata(el){
var comment_id=el.attr('data-commentId');
var comment_user=el.attr('data-commentUser');
var who_like=el.attr('data-whoLike');
var like_num_in_comment=el.attr('data-likeNuminComment');
};
从HTML中删除onclick="getsomedata(this)"