自动更改div或div';s内容javascript
我想要一个脚本,可以自动更改我的整个div或div的内容。请注意,只是javascript,jQuery 我试过:自动更改div或div';s内容javascript,javascript,Javascript,我想要一个脚本,可以自动更改我的整个div或div的内容。请注意,只是javascript,jQuery 我试过: <script type="text/javascript"> var kickoff = new Date("May 10, 2015 23:18:00"), timerContainer = document.getElementById('timerContent'), timer; // Added for visibility in the global sc
<script type="text/javascript">
var kickoff = new Date("May 10, 2015 23:18:00"),
timerContainer = document.getElementById('timerContent'),
timer; // Added for visibility in the global scope.
function cdtd() {
var now = new Date(),
timeDiff = kickoff.getTime() - now.getTime();
if (timeDiff <= 0) {
clearTimeout(timer);
timerContainer.innerHTML = '<div>KICK OFF!!!!</div> <img src="img1.gif" />';
} else {
// This style of declaration is just preference.
var seconds = Math.floor(timeDiff / 1000),
minutes = Math.floor(seconds / 60),
hours = Math.floor(minutes / 60),
days = Math.floor(hours / 24);
if (seconds < 10) seconds = "0" + seconds;
if (minutes < 10) minutes = "0" + minutes;
if (hours < 10) hours = "0" + hours;
if (days < 10) days = "0" + days;
// Using an array simplifies the process of creating the text
// In some browsers this is more performant than using '' + ''
// In other browsers it's not, in reality the difference marginal in
// small iterations like this one.
var textTemplateArray = [
days, 'Days',
minutes, 'Minutes',
hours, 'Hours',
seconds, 'Seconds'
];
timerContainer.innerHTML = textTemplateArray.join(' ');
}
}
timer = setInterval(cdtd, 1000);
风险值启动=新日期(“2015年5月10日23:18:00”),
timerContainer=document.getElementById('timerContent'),
计时器;//为在全局范围内的可见性而添加。
函数cdtd(){
var now=新日期(),
timeDiff=kickoff.getTime()-now.getTime();
if(timeDiff我认为我的假设是正确的,您希望javascript将
元素中的文本更改为某个变量的值,并每隔一秒/任何时间帧重复此操作以更新显示的值
可以这样做:
setInterval(function(){document.getElementById('id').innerHTML = 'New text'},1000);
每秒钟(1000毫秒)将重复以下操作:
其中“newtext”应替换为变量名您能否澄清“更改我的div”的含义?以何种方式更改?
document.getElementById('id').innerHTML = 'New text'