脚本在Safari中不起作用 [英] Script doesn't work in Safari

查看:470
本文介绍了脚本在Safari中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在I.E.中工作正常的短脚本。和Firefox,但不是在
Safari中。它应该在

网页上打印一个不断更新的计数器。任何想法如何让它在Safari中工作?该脚本使用

Date对象,尤其是Date.getTime()。这有什么可做的吗

有问题吗?


谢谢,


E

//这个< form>与脚本放在同一个HTML页面中......

< form name =" counter" style =" margin:0; padding:0;">

< input type =" text"名称= QUOT;量QUOT;值= QUOT; 0"大小= QUOT; 40" readonly =" true"

style =" margin:0; padding:0; border:none; font-size:24px; color:#cc0000;">

< / form>


//这是脚本......

< script type =" text / javascript">


// formatNumber函数来自Danny Goodman的JavaScript

Cookbook。

[...还剩一些代码在这里为了简洁......]


var startingDate = new Date(2005,0,1);

var startingDebt = 1000000000;

函数updateCounter(){

var nowDate = new Date();

var debtTimeInSeconds =(nowDate.getTime() -

startingDate.getTime())/ 1000;

var newValue = startingDebt +(d​​ebtTimeInSeconds * 3.47);

document.counter.amount.value =" $" + formatNumber(newValue,2);

}

updateCounter();

intervalID = setInterval(" updateCounter()",1000 );

< / script>

I''ve got a short script that works fine in I.E. and Firefox, but not in
Safari. It is supposed to print a constantly-updating counter on the
webpage. Any ideas how to get it to work in Safari? The script uses the
Date object, especially Date.getTime(). Could that have something to do
with the problem?

Thanks,

E
// This <form> is put into the same HTML page as the script...
<form name="counter" style="margin: 0; padding: 0;">
<input type="text" name="amount" value="0" size="40" readonly="true"
style="margin:0;padding:0;border:none;font-size:24px;color:#cc0000;">
</form>

// Here is the script...
<script type="text/javascript">

// The formatNumber function comes from Danny Goodman''s JavaScript
Cookbook.
[ ... some code left out here for brevity ... ]

var startingDate = new Date(2005, 0, 1);
var startingDebt = 1000000000;
function updateCounter(){
var nowDate = new Date();
var debtTimeInSeconds = (nowDate.getTime() -
startingDate.getTime())/1000;
var newValue = startingDebt + (debtTimeInSeconds * 3.47);
document.counter.amount.value = "$" + formatNumber(newValue, 2);
}
updateCounter();
intervalID = setInterval("updateCounter()", 1000);
</script>

推荐答案

" + formatNumber(newValue,2);

}

updateCounter();

intervalID = setInterval(" updateCounter()",1000 );

< / script>

" + formatNumber(newValue, 2);
}
updateCounter();
intervalID = setInterval("updateCounter()", 1000);
</script>


elektrophyte写道:
elektrophyte wrote:
我有一个在IE中运行良好的短脚本和Firefox,但不在Safari中。它应该在
网页上打印一个不断更新的计数器。任何想法如何让它在Safari中工作?该脚本使用
Date对象,尤其是Date.getTime()。这有什么可以解决的问题吗?

谢谢,


//这个< form>被放入与脚本相同的HTML页面中......
< form name =" counter" style =" margin:0; padding:0;">
< input type =" text"名称= QUOT;量QUOT;值= QUOT; 0"大小= QUOT; 40" readonly =" true"
style =" margin:0; padding:0; border:none; font-size:24px; color:#cc0000;">
< / form>

//这是脚本......
< script type =" text / javascript">

// formatNumber函数来自Danny Goodman的JavaScript
Cookbook。
[...为了简洁起见,这里省略了一些代码...]

var startingDate = new Date(2005,0,1) ;
var startingDebt = 1000000000;
函数updateCounter(){
var nowDate = new Date();
var debtTimeInSeconds =(nowDate.getTime() -
startingDate .getTime())/ 1000;


手动包装已发布的代码大约70个字符,允许

自动换行可能导致问题,空格缩进不是标签。

你也不需要''getTime()''方法:


var debtTimeInSeconds =(nowDate - startingDate)/ 1000;


var newValue = startingDebt +(d​​ebtTimeInSeconds * 3.47);
document.counter.amount.value ="
I''ve got a short script that works fine in I.E. and Firefox, but not in
Safari. It is supposed to print a constantly-updating counter on the
webpage. Any ideas how to get it to work in Safari? The script uses the
Date object, especially Date.getTime(). Could that have something to do
with the problem?

Thanks,

E
// This <form> is put into the same HTML page as the script...
<form name="counter" style="margin: 0; padding: 0;">
<input type="text" name="amount" value="0" size="40" readonly="true"
style="margin:0;padding:0;border:none;font-size:24px;color:#cc0000;">
</form>

// Here is the script...
<script type="text/javascript">

// The formatNumber function comes from Danny Goodman''s JavaScript
Cookbook.
[ ... some code left out here for brevity ... ]

var startingDate = new Date(2005, 0, 1);
var startingDebt = 1000000000;
function updateCounter(){
var nowDate = new Date();
var debtTimeInSeconds = (nowDate.getTime() -
startingDate.getTime())/1000;
Manually wrap posted code at about 70 characters, allowing
auto-wrapping can cause problems and with space indents not tabs.

You also don''t need the ''getTime()'' method:

var debtTimeInSeconds = (nowDate - startingDate)/1000;

var newValue = startingDebt + (debtTimeInSeconds * 3.47);
document.counter.amount.value = "


" + formatNumber(newValue,2);
}
updateCounter();
intervalID = setInterval(" updateCounter()",1000);
< / script>
" + formatNumber(newValue, 2);
}
updateCounter();
intervalID = setInterval("updateCounter()", 1000);
</script>




如果你删除了

''formatNumber()''函数,它在Safari 1.0.3中运行正常。发布它以进行修复。

-

RobG



It works fine in Safari 1.0.3 as far as I can tell if you remove the
''formatNumber()'' function. Post it for a fix.
--
RobG


这篇关于脚本在Safari中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆