如何调用一个jquery单击按钮前的JS功能(通过选择点击) [英] How to call a JS function before a jquery button click(click through selector)
本文介绍了如何调用一个jquery单击按钮前的JS功能(通过选择点击)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要调用一个JS函数单击按钮时,然后继续下面的的jQuery
脚本的执行
I want to call a JS function when a button is clicked and then continue execution of below jquery
script
形式:
<form id="my_form">
<button type="button" id="Bshift" onclick="validation()">Clear</button>
</form>
纯JS功能:
function validation(){
// this has to be executed first
// do something here..
}
jQuery的:
$(document).ready(function(){
$('#Bshift').submit(function(){
// this has to be executed second
// do something here.
}
});
我想知道的是我如何执行我的功能我的jQuery之前提交
I would like to know is how I execute my function before my jquery submit.
推荐答案
HTML
<form id="my_form">
<button type="button" id="Bshift">Clear</button>
</form>
JS:
$(document).ready(function(){
$('#Bshift').on('click', function(){ // I think this should be click event because you're not submitting your page you're just clearing it based on "CLEAR"
validation();
}
function validation(){
do something here..
}
}
注意:您的函数必须是事件触发外
Note: Your function must be outside the event triggers.
这篇关于如何调用一个jquery单击按钮前的JS功能(通过选择点击)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文