【问题标题】:triggering jQuery show on focus not working on mobile触发jQuery显示焦点不在移动设备上
【发布时间】:2017-02-15 12:18:47
【问题描述】:

当我关注一个显示 'other' 的复选框时,我会触发显示一个文本区域,因此用户只有在从其他复选框中单击该选项时才需要它。 (http://air.abricot-production.com/alliance-of-independent-restaurants/restaurant-membership-application.html)。

    <script>
    $(document).ready(function(){
        $(".BusTypeOtherTextArea").hide();
            $(".BusTypeOther").focus(function () {
                $(".BusTypeOtherTextArea").show("fast");
                return false;
            });
        });
    </script> 

focus 在台式机上可以正常工作,但在移动设备上不行?如果我使用 click 它适用于两者,但不会选中复选框。如何使这项工作适用于移动设备?

【问题讨论】:

    标签: jquery click focus show


    【解决方案1】:

    我认为一个解决方法,我认为它应该是这样的:

    $('.checkBox').click(function(){
      if($(this).prop('checked')) {
        // show textarea
      } else {
        // hide
      }
    });
    

    我建议不要使用焦点,尤其是在您在移动(平板电脑/手机)设备中没有此手势的情况下。

    【讨论】:

    • 我的 testarea 一开始就不再隐藏。抱歉,似乎无法格式化为带有缩进等的代码 $(document).ready(function(){ $(".BusTypeOtherTextArea").hide(); $(".BusTypeOther").click(function () { if ($(this).prop("checked")) { $(".BusTypeOtherTextArea").show("fast"); } else { $(".BusTypeOtherTextArea").hide("fast"); }); });
    • 感谢 Ben,.one('click focus', function() 似乎是一个很好的解决方案。
    【解决方案2】:

    此解决方案有效:

    $(document).ready(function(){
        $(".BusTypeOtherTextArea").hide();
            $(".BusTypeOther").one('click focus', function() {
                $(".BusTypeOtherTextArea").show("fast");
                return false;
            });
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多