简体   繁体   English

jQuery .hide()导致第2个按钮的幽灵touchstart“单击”

[英]jQuery .hide() causing a ghost touchstart “click” of 2nd button

I have two buttons on a page, I need to hide a "calculate" button so that it is not clicked again and again, but rather users select a "reset" button. 我在页面上有两个按钮,我需要隐藏一个“计算”按钮,这样才不会一次又一次地单击它,而是用户选择一个“重置”按钮。

This works great if both buttons are showing but if I hide the calculate button, once it has completed its work, it somehow is automatically executing the reset button even though the reset button is not being clicked. 如果两个按钮都同时显示,则效果很好,但是如果我隐藏了计算按钮,则一旦完成工作,即使未单击重置按钮,它也将以某种方式自动执行重置按钮。

This only happens on touch devices . 这仅在触摸设备上发生 This works fine if it is run from a browser. 如果它是从浏览器运行的,则可以正常工作。 It is only the touch devices (ex. iPhone) where the issue is occurring. 发生此问题的仅是触摸设备(例如iPhone)。 Any clues? 有什么线索吗? I am using jquery-2.1.1.min 我正在使用jquery-2.1.1.min

Here is my calculate button: 这是我的计算按钮:

$(document).on( 'touchstart click' ,  '#calculate' ,  function  () {
// do stuff
//hide button now that we are done so users don't keep clicking
$( '#calculate' ).hide();
});

Here is my reset button: 这是我的重置按钮:

$(document).on( 'touchstart click' ,  '#reset' ,  function  () {
$( "input.form-control" ).val(0);
});

Here is my working example: 这是我的工作示例:

http://investingcalculator.azurewebsites.net/ http://investingcalculator.azurewebsites.net/

Did you try without delegating? 您尝试不委派吗?

$('#calculate').on( 'touchstart click',  function  () {
// do stuff
//hide button now that we are done so users don't keep clicking
$( '#calculate' ).hide();
});

$('#reset').on( 'touchstart click',  function  () {
  $( "input.form-control" ).val(0);
});

It ends up that I didn't need the touch start. 最终我不需要触摸开始。 This is working: 这正在工作:

$('#calculate').on( 'click',  function  () {
// do stuff
//hide button now that we are done so users don't keep clicking
$( '#calculate' ).hide();
});

$('#reset').on( 'click',  function  () {
$( "input.form-control" ).val(0);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM