[英]jQuery doesn't work on Firefox but works on Chrome
I have this jQuery
code: 我有这个jQuery
代码:
function action(action){
event.preventDefault();
var products = $("#check-list input:checkbox:checked").map(function(){
return $(this).val();
}).get();
var string = JSON.stringify(products);
var table = $('#table').val();
if(products.length != '0' || action === 'old-all'){
$.ajax({
type: 'post',
url: 'app/toolbar.php',
data: {action:action, table:table, ids:string},
success:function(data){
localStorage.setItem('notify', data);
location.reload();
},
});
} else{
notify('You must choose an element first');
}
}
I'm using jQuery 3.3.1
. 我正在使用jQuery 3.3.1
。
If i click a button without checking a checkbox i should get You must choose an element first
but if i choose an element the toolbar.php
should run and do the thing it has to be done(according to which button was pressed: 如果我单击一个按钮而没有选中复选框我应该得到You must choose an element first
但如果我选择一个元素, toolbar.php
应该运行并做必须完成的事情(根据按下的按钮:
<button class="grey-btn" onClick="action('delete')">Delete</button>
<button class="grey-btn" onClick="action('update')">Update</button>
It works on Chrome
perfectly but it doesn't work on Firefox
. 它完全适用于Chrome
,但它不适用于Firefox
。 I was trying some answers that i found on some other similar 'works on chrome but not on firefox' questions but neither one of them worked :( 我正在尝试一些答案,我在其他类似的'铬上的作品,但没有在Firefox上'找到答案,但他们都没有工作:(
You do not define event so that is your problem. 您没有定义事件,因此这是您的问题。 Get away from using inline event handlers and bind it with jQuery. 远离使用内联事件处理程序并将其与jQuery绑定。
$("[data-action]").on("click", function (event) { event.preventDefault(); var btn = $(this); var action = btn.data("action"); console.log(action); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="grey-btn" data-action='delete'>Delete</button> <button class="grey-btn" data-action='update'>Update</button>
If you really want to use inline event handlers than do 如果你真的想使用内联事件处理程序而不是
function action (event, method) { event.preventDefault(); console.log(method); }
<button class="grey-btn" onClick="action(event, 'delete')">Delete</button> <button class="grey-btn" onClick="action(event, 'update')">Update</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.