简体   繁体   English

无法在Cordova中单击div

[英]Can't click div in cordova

Helo! 直升机!

I am creating a cordova app, and run in to the following issue on S4 Mini, android 4.2.2. 我正在创建一个cordova应用,并在android 4.2.2的S4 Mini上运行以下问题。 I have a div element 我有一个div元素

<div class="switch" id="switchOff" onclick="clicked()">
  <img alt="switch off" src="img/70/switchOff.png" />
</div>

Theres no way I was able to react to a click event. 我无法对点击事件做出反应。 I tried every possible way I know. 我尝试了所有可能的方法。

  $('#switchOff').css('position', 'relative');
  $('#switchOff').css('zIndex','10000');
  var foo = document.getElementById("switchOff");
  console.log('zindex: ' + $(foo).css('zIndex')); //gives it back, so it works
  $('#switchOff').bind('click',function(){
      alert('Bind is the winner');
  });

  foo.click = function(){
      alert('Native click is the winner');
  }

  $(document).on('click','#switchOff',function(){
            alert('Holaon');
  });

  document.getElementById("switchOff").addEventListener('click', function(){
      alert('eventlistener is a winner');
  }, false);

The most strange thing is that I can even change the attributes of that div, so the selector works, and its already loaded to the dom. 最奇怪的是,我什至可以更改div的属性,因此选择器可以正常工作,并且它已经加载到dom中。 Another strange thing is that it works well on other devices. 另一个奇怪的是,它可以在其他设备上很好地工作。 (motorola defy, xperia tablez-z, atrix). (摩托罗拉defy,xperia tablez-z,Atrix)。

I run out of ideas, can someone help with this? 我没办法了,有人可以帮忙吗?

where is your clicked() defined? 您的clicked()在哪里定义? Did you wraped the whole code in the jquery ready listener like this?: 您是否将整个代码这样包装在准备就绪的jQuery侦听器中?:

$(function(){
     $('#switchOff').click(function(){
         //do something
     });
});

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

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