简体   繁体   English

使用Javascript / jQuery单击一次

[英]Click once with with Javascript / jQuery

I have the following JS: 我有以下JS:

jQuery(function($){
  $( "#product_filters_form_sizes_medeiumnnarrow" ).click()
  $('menu.pills').on('click', 'a', function(event){
    $pill = $(this);
    $('form.product_filters_form')
      .find("input[value='"+$pill.data('filterId')+"']")
      .attr('checked', false).trigger('change');
  })
});

It does exactly what I need it do, which is to select '#product_filters_form_sizes_mediumnarrow' only issue is it keeps on clicking and the pages reloads each time. 它确实'#product_filters_form_sizes_mediumnarrow'我的需要,那就是选择'#product_filters_form_sizes_mediumnarrow'唯一的问题是它会不断点击,并且每次都会重新加载页面。

My questions is: is there a way to only click once? 我的问题是:有没有办法只单击一次?

Thank you and any help would be greatly appreciated. 谢谢您,任何帮助将不胜感激。

  <li class="product_filter input required" id="product_filters_form_sizes_input"><fieldset class="choices"><legend class="label"><label>Sizes</label></legend><input id="product_filters_form_sizes_none" name="product_filters_form[sizes][]" type="hidden" value=""><ol class="choices-group"><li class="choice"><label for="product_filters_form_sizes_mediumnarrow"><input id="product_filters_form_sizes_mediumnarrow" name="product_filters_form[sizes][]" type="checkbox" value="medium/narrow"><i class="icon checked-indicator"></i>MEDIUM/NARROW</label></li>

if you need a function that does something once in jQuery it's called one. 如果您需要一个在jQuery中执行一次操作的函数,则称为一个。 you're probably looking for: 您可能正在寻找:

$('#product_filters_form_sizes_mediumnarrow').one('click');

your problem is probably happening because a reload is happening and this is the line that immediately happens. 您的问题可能正在发生,因为正在发生重新加载,并且这是立即发生的行。

so my question to you buddy is what does the click actually do? 因此,我对您的伙伴提出的问题是点击实际上是做什么的? i guess it's a form submission. 我想这是一个表单提交。

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

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