gpt4 book ai didi

javascript - onclick 不适用于按钮

转载 作者:行者123 更新时间:2023-12-03 10:18:56 29 4
gpt4 key购买 nike

我试图让 JavaScript 函数在按下删除按钮时起作用,但该函数似乎没有运行。

这是按钮

 <button class="tiny" id="bookmark_delete" onlclick="ajax_bookmark()">Delete</button> 

这是 JS

    function ajax_bookmark(){
var abc = $('#b_delete').val();
var cde = $('#currect_req_b_id').val();
$.ajax({
type: "GET",
url: "delete_bookmark",
data: {
d:abc,
d1:cde
},
error:function(){

},
dataType: 'json',
//beforeSend:function(){},
//complete:function(o,s){},
success:function(data){
location.href ="/bookmarks/bookmark"
},
type: 'get'
});
}
</script>

最佳答案

您在onclick中似乎有一个拼写错误。按钮标签的属性:

<button class="tiny" id="bookmark_delete" onlclick="ajax_bookmark()">Delete</button>

应该是:

<button class="tiny" id="bookmark_delete" onclick="ajax_bookmark()">Delete</button>

工作片段:

function foo(){
$('button').html('I was clicked!');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="foo()">DoFoo</button>

关于javascript - onclick 不适用于按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29732507/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com