function divFunction() {
$('#edit-modal').modal();
}
如何在此代码中添加事件?我试过这个,但它在firefox中显示错误:
typeerror:event undefined
function divFunction(event) {
event.stopPropagation();
var postBody = event.target.parentNode.parentNode.childNodes[1].textContent;
$('#post-body').val(postBody);
$('#edit-modal').modal();
}
这就是我调用函数的方式:
@if(Auth::user()== $post->user)
<a href="#" name="edit" class="edit" onClick="divFunction()">Edit | </a>
<a href="{{ route('post.delete', ['post_id' => $post->id]) }} ">Delete | </a>
@endif
答案 0 :(得分:1)
您需要将事件对象传递给函数
<a href="#" name="edit" class="edit" onClick="divFunction(event)">Edit | </a>