无法使用jquery在iPhone上禁用选择

时间:2014-02-20 04:44:49

标签: jquery ios

我正在尝试获取以下代码,它只是运行两个不同脚本的两个按钮。按下第一个按钮时,第二个按钮变为启用状态。第二个按钮必须按住10秒钟,而计数器在第二个脚本激活之前倒计时。这在我的笔记本电脑上运行良好,但我需要让它在我的iPhone上工作。当我尝试按住第二个按钮时,会出现文本选择。按下第二个按钮一次然后松开将导致倒计时自动执行,但我只想在按下按钮时进行倒计时。

我尝试了这个CSS -webkit-user-select: none;,但除非我做错了,否则无法让它工作。我想将此应用于整个文档。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">

var countDownSecs = 10;
var check = null;

function printCountDown() {
    if (check == null && document.getElementById("counter").innerHTML != 'Launched!') {
        var cnt = countDownSecs;
            check = setInterval(function () {
                cnt -= 1;
                document.getElementById("counter").innerHTML = cnt;
                if (cnt == 0) {
                launch();
                  }
            }, 1000);
    }
}

function stop() {
    clearInterval(check);
    check = null;
    document.getElementById("counter").innerHTML = countDownSecs;
}

function launch() {
    $.ajax({
            type: "POST",
            url: "cgi-bin/launch.cgi"
        })
    clearInterval(check);
    check = null;
    document.getElementById("counter").innerHTML = 'Launched!';
}

    function ckcont() {
            $.ajax({
                    type: "POST",
                    url: "cgi-bin/ckcont.cgi"
                    })
}

</script>
</head>
<body>

<button id="continuity">Check Continuity</button>

<script>
$(document).ready(function(){
  $("#continuity").click(function(){
$("p").toggleClass("main");
$("#launch").removeAttr("disabled");
ckcont();
  });
});
</script>

<button id="launch" disabled="disabled">&nbsp;&nbsp;&nbsp;Count Down:&nbsp;
<span id="counter"><script>document.write(countDownSecs);</script></span>
</button>

<script>
$("#launch").bind( "mousedown touchstart", function() {
if (check != null){
    stop();
}
//$( "body" ).append( "<span style='color:#f00;'>Mouse up.</span><br>" );
});

$("#launch").bind( "mouseup touchend", function() {
printCountDown();
//$( "body" ).append( "<span style='color:#00f;'>Mouse down.</span><br>" );
});
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

使用它:

-webkit-touch-callout: none;