单击按钮后我必须调用相同的函数,但不起作用
关闭 jQuery 函数触发事件后未调用
如何在 jQuery 中调用 click 函数
请任何人给我建议来解决
$(document).ready(function(){
$("input").on("click",function(){
$("input").after(" Text marked!");
});
$("input").off("click");
$("button").on("dblclick",function(){
$("input").trigger("click");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<input type="text" value="Hello World"><br><br>
<button>Trigger the select event for the input field</button>
我添加示例为
javascript
,请尝试理解该示例,以便您可以在您的项目中使用它。
function btnClick(e) {
const click = document.getElementById('click');
click.innerText = 'button has been clicked';
setTimeout(() => {
alert('i will call action1');
action1();
}, 1000)
}
function action1() {
const action1 = document.getElementById('action1');
action1.innerText = 'action1 has been called';
setTimeout(() => {
alert('now, i will call action2')
action2();
}, 1000)
}
function action2() {
const action2 = document.getElementById('action2');
action2.innerText = 'action2 has been clicked';
setTimeout(() => {
alert('Good job!')
}, 1000)
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<ul>
<li id="click">No action yet</li>
<li id="action1">No action yet</li>
<li id="action2">No action yet</li>
</ul>
<button onclick="btnClick(this)">Click To start calling action</button>
</body>
</html>