[英]Javascript custom event fire from a function with returning false
I have following form code, and I have to prevent the form submission and after firing a custom event.我有以下表单代码,我必须阻止表单提交和触发自定义事件之后。 I have also written a Javascript on submit function triggering that event and then return false.我还编写了一个关于提交函数触发该事件然后返回 false 的 Javascript。 Please help if I am doing wrong.如果我做错了,请帮助。
form html:表单html:
<form class="form-inline" action="" name="filterform">
<div class="row">
<?php foreach($formatted_post_type as $filters){?>
<div class="checkbox">
<label class="checkbox-inline" style="line-height:40px;">
<input type="checkbox" name="filters[posttype][]" value="<?php echo $filters['slug']?>" onclick="refresh_posttypes();" />
<?php echo $filters['name']?></label>
</div>
<?php }?>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" class="btn btn-primary btn-sm" value="Apply">
</div>
</div>
</form>
javascript code: javascript代码:
jQuery(document).ready(function(){
jQuery('form[name="filterform"]').on('submit', function(e){
jQuery(document).triggerHandler('favorites-update-all-lists', function(e){
e.preventDefault();
});
return false;
});
});
try with this试试这个
$(function() {
$('form[name="filterform"]').on('submit', function(e) {
$(document).triggerHandler('favorites-update-all-lists', function() {
e.preventDefault();
});
});
});
you are using e in both anonymous functions您在两个匿名函数中都使用了 e
Try moving e.preventDefault();
尝试移动e.preventDefault();
right after the submit handler:在提交处理程序之后:
jQuery(document).ready(function(){
jQuery('form[name="filterform"]').on('submit', function(e){
e.preventDefault();
jQuery(document).triggerHandler('favorites-update-all-lists', function(e){
});
return false;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.