Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript,如果在iphone上不起作用_Javascript_Jquery_Iphone_If Statement - Fatal编程技术网

javascript,如果在iphone上不起作用

javascript,如果在iphone上不起作用,javascript,jquery,iphone,if-statement,Javascript,Jquery,Iphone,If Statement,出于某种原因,以下jquery代码在浏览器中工作,但在我的iPhone上不工作: $j(".timer").each(function() { var htmlString = $j( this ).html(); var stringetje = htmlString.split(';'); var seconds = new Date().getTime() / 1000; var timestamp = stringetje[0]-secon

出于某种原因,以下jquery代码在浏览器中工作,但在我的iPhone上不工作:

        $j(".timer").each(function() {
    var htmlString = $j( this ).html();
    var stringetje = htmlString.split(';');
    var seconds = new Date().getTime() / 1000;
    var timestamp = stringetje[0]-seconds;
    var numdays = Math.floor(timestamp / 86400)+" day(s) left";
    var numhours = Math.floor((timestamp % 86400) / 3600)+" hour(s) left";
    var numminutes = Math.floor(((timestamp % 86400) % 3600) / 60)+" minutes left";
// Till here everything works fine on iPhone!
    if (timestamp > 86400) { 
    jQuery("."+stringetje[2]).text(numdays); 
// alert('test'); is not showing on iPhone
     }
    if (timestamp < 86400) { 
    jQuery("."+stringetje[2]).text(numhours); 
    }
    if (timestamp < 3600) { 
    jQuery("."+stringetje[2]).text(numminutes); 
     }
    if (timestamp < 0) { 
    jQuery("."+stringetje[2]).text("Deal expired"); 
    } 
$j(“.timer”)。每个(函数(){
var htmlString=$j(this.html();
var stringetje=htmlString.split(“;”);
var seconds=new Date().getTime()/1000;
var timestamp=stringetje[0]-秒;
var numdays=数学楼层(时间戳/86400)+“剩余天数”;
var numhours=Math.floor((时间戳%86400)/3600)+“剩余小时”;
var numminutes=Math.floor((时间戳%86400)%3600)/60)+“还剩几分钟”;
//在这里,iPhone上的一切都很好!
如果(时间戳>86400){
jQuery(“.”+stringetje[2])文本(numdays);
//警报(“测试”);未在iPhone上显示
}
如果(时间戳<86400){
jQuery(“.”+stringetje[2])文本(numhours);
}
如果(时间戳<3600){
jQuery(“.”+stringetje[2])文本(numminutes);
}
如果(时间戳<0){
jQuery(“.”+stringetje[2])文本(“交易到期”);
} 
stringetje[2]是一个javascript变量,我使用“.”表示它应该以类为目标

当使用可变时间戳时,if语句出现了一些错误。有人知道为什么它不能在iPhone上工作吗


另外,它正在Android和Windows手机以及所有常规桌面浏览器(Chrome、Firefox、IE)上运行问题是iPhone显然在源代码中添加了html,这是我没有预料到的。html被更改为一个可点击的链接,就像它是一个电话号码一样,例如
,而浏览器将其显示为
14121421;14121421;14121421

为了防止这种情况发生,我更改了以下内容:

 var htmlString = $j( this ).html();
为此:

 var htmlString = $j( this ).text();

学分归Marc B(见备注)。

完成任何基本调试,例如执行
警报(时间戳)
查看iDevices上的值是多少?另外,
stringetje
似乎将是一个字符串数组,因此您正在执行
string-int
。也许JS引擎正在吐这个值。是的,正如您在我尝试放置alert()的代码中看到的那样;在某些地方,我发现在if语句之前,一切都很好。不幸的是,我无法使用iOS的调试控制台,因为我没有mac可以使用web inspector。关于你的字符串注释,我尝试使用Number(timestamp),但这也不起作用。我再次测试了
alert(timestamp);
它告诉我“NaN”。然后,我测试了
警报(isNaN(timestamp));
,这给了我“true”。因此,请按照您的方式返回该链:
警报(stringetje[0]);警报(秒);
,等等……浏览器将呈现该html。执行
查看源代码
以查看服务器中真正出现的内容。您可能需要
$j(this)。text()
仅获取实际文本内容。