【问题标题】:jQuery event is not properly working in mobile (iOS, Android)jQuery 事件在移动设备(iOS、Android)中无法正常工作
【发布时间】:2017-07-29 22:46:59
【问题描述】:

jQuery 事件在浏览器中完全没有问题。

但是,在移动浏览器(iOS 和 Android)中,除非我单击按钮 1,否则它无法正确识别 jQuery 事件。如何修复它以便在移动设备(如浏览器)中正​​常工作 jQuery click 事件?

$(function(){
    	
      $(".btn2").css({"display":"none"});
      
      $("body").click(function(){	
					if($("#menuSelect option:selected").index() > 0){
						$(".btn1").css({"display":"none"});
						$(".btn2").css({"display":"block"});					
					}
			})
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  	<section class="section">
					<select id="menuSelect">
						<option value="menu" selected="selected">choose one </option>
						<option value="a">a</option>
						<option value="b">b</option>
						<option value="c">c</option>
						<option value="d">d</option>
					</select>
    </section>
    
    <div>
          <p class="btn1 button"><input type="button"     value="button1" onclick="fn_popup_open('area_popup2');"/></p>
				<p class="btn2"><input type="button" value="button2" id="Apply"/></p>

【问题讨论】:

    标签: android jquery ios


    【解决方案1】:

    试试看:

    var myElement= document.getElementById('myelement');
    
    myElement.addEventListener('click', function() {
    
    
    alert('Hello world');
    
    }, false);
    

    【讨论】:

      【解决方案2】:

      试试:

      $(function(){
      
            $(".btn2").css({"display":"none"});
      
            $("#menuSelect").change(function(){   
                          if($("#menuSelect option:selected").index() > 0){
                              $(".btn1").css({"display":"none"});
                              $(".btn2").css({"display":"block"});                    
                          } else {
                $(".btn1").css({"display":"block"});
                              $(".btn2").css({"display":"none"}); 
                }
                  })
        });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-28
        • 1970-01-01
        • 2023-03-24
        • 2020-10-16
        相关资源
        最近更新 更多