我有一个绑定点击事件的按钮,如下面的代码:
jQuery(function(){
$("#btnSubmit").on("click", function(){
//code here
})}
当我点击浏览器中的按钮时,它不会执行我的代码。但是当我打开开发人员工具并输入:$("#btnSubmit")[0].click()
时,它会执行我的代码。
任何指导都会有所帮助。
答案 0 :(得分:0)
你能试试这个code吗?
Attendance
请记住,在您的HTML中,您需要一个像这样的按钮
jQuery(function(){
$("#btnSubmit").on("click", function(){
console.log("hello");
});
});
答案 1 :(得分:0)
HTML:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<button type="button" class="btn btn-default" id="btnSubmit">Submit</button>
</body>
JS:
$(document).ready(function() {
$("#btnSubmit").click(function() {
alert("hello");
});
});
工作JSFiddle: https://jsfiddle.net/codeforwin/yj9m6mLv/
答案 2 :(得分:-1)
试试这个:
$("#btnSubmit").click(function(){
//do stuff here
});