在之前的元素中,使用 touchstart 和 touchend 事件修改按钮的 css 的以下代码没有问题:
<script>
$('input[type="button"]').on('touchstart', function(e){
$(this).css('background-color','#49D623');
});
$('input[type="button"]').on('touchend', function(e){
$(this).css('background-color','');
});
</script>
这是在使用 2.9.0 版的 iOS cordova 元素中
因为我已经升级到 cordova 3.2 并且正在使用 jquery mobile 1.4.0 和 jquery 1.10.2,所以上面的代码不再有效。
我已经尝试过 .on(touchstart
和 .bind(touchstart
和 .live(touchstart
与 jquery 1.8 一起工作但在 1.9 中被弃用.我也尝试过使用按钮的id,但那也不起作用。
我知道 touchstart 正在被识别,因为我已经测试过它可以触发其他功能,而且它的效果非常好,但不是为了这个。
这是按钮在我的 html 中的显示方式:
<input type="button" id="submit" data-role="none">
相关按钮的CSS:
input[type="button"] {
-webkit-appearance: none;
border-radius: 0px;
width: 92%;
margin-top: 3%;
margin-left: 5%;
background-color: rgba(23,24,54,1.00);
padding: 10px;
border-width: 1px;
border-color:rgba(88,88,88,1.00);
font-size: 1em;
color: #FFFFFF;
font-family: 'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
background-image: url(../img/padlock2.png);
background-size: 20px;
background-repeat:no-repeat;
background-position: 50% 50%;
}
我的 html 文件的头部引用了以下内容:
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.mobile-1.4.0.min.js"></script>
<script src="cordova.js"></script>
<script src="cordova_plugins.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquerymobile1.4rc1.css">
<link rel="stylesheet" type="text/css" href="css/login.css">
<link rel="stylesheet" type="text/css" href="css/globalstyles.css">
我在这里错过了什么?
最佳答案
我不确定它是否能解决您的问题,但 .live() 方法已被弃用。尝试使用 .on() 方法代替它。还可以尝试用 mousedown 和 mouseup 替换 touchstart 和 touchend,看看是否能解决问题。这是一个plunker where i got something similar to work
关于javascript - Touchstart 和 touchend 不能在 iOS 上使用 jquery mobile 和 cordova,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21093816/