本文目录一览:
这段JS代码怎么能让它循环呢?
!--下面是向左滚动代码--
div id="colee_left" style="overflow:hidden;width:500px;"
table cellpadding="0" cellspacing="0" border="0"
trtd id="colee_left1" valign="top" align="center"
table cellpadding="2" cellspacing="0" border="0"
tr align="center"
tdpimg src=""/p/td
tdpimg src=""/p/td
tdpimg src=""/p/td
tdpimg src=""/p/td
tdpimg src=""/p/td
tdpimg src=""/p/td
tdpimg src=""/p/td
/tr
/table
/td
td id="colee_left2" valign="top"/td
/tr
/table
/div
script
//使用div时,请保证colee_left2与colee_left1是在同一行上.
var speed=30//速度数值越大速度越慢
var colee_left2=document.getElementById("colee_left2");
var colee_left1=document.getElementById("colee_left1");
var colee_left=document.getElementById("colee_left");
colee_left2.innerHTML=colee_left1.innerHTML
function Marquee3(){
if(colee_left2.offsetWidth-colee_left.scrollLeft=0)//offsetWidth 是对象的可见宽度
colee_left.scrollLeft-=colee_left1.offsetWidth//scrollWidth 是对象的实际内容的宽,不包边线宽度
else{
colee_left.scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
colee_left.onmouseover=function()
colee_left.onmouseout=function()
/script
!--向左滚动代码结束-- 你试试这个 我一直用的
怎么用JS实现 按钮功能的循环执行?
用JS实现
点击‘提交’
按钮变成
‘继续添加’同时文本框变灰且只可读,
再次点击
‘继续添加’
文本框变回原来可写,按钮变成‘提交’。一直可以循环执行:
var
bbb
=
document.getElementById('btn1');
bbb.onclick
=
function()
{
var
ttt
=
document.getElementById('btn1').value;
if
(ttt
==
'提交')
{
isreadonly();
changebutton1();
}
else
if
(ttt
==
'继续添加')
{
readwrite();
changebutton2();
}
};
function
isreadonly()
{
var
obj
=
document.getElementById("in1");
obj.setAttribute("readOnly",
true);
obj.style.backgroundColor
=
"#d2d2d2";
var
obj
=
document.getElementById("in2");
obj.setAttribute("readOnly",
true);
obj.style.backgroundColor
=
"#d2d2d2";
var
obj
=
document.getElementById("in3");
obj.setAttribute("readOnly",
true);
obj.style.backgroundColor
=
"#d2d2d2";
}
function
readwrite()
{
var
obj
=
document.getElementById("in1");
obj.setAttribute("readOnly",
false);
obj.style.backgroundColor
=
"#ffffff";
var
obj
=
document.getElementById("in2");
obj.setAttribute("readOnly",
false);
obj.style.backgroundColor
=
"#ffffff";
var
obj
=
document.getElementById("in3");
obj.setAttribute("readOnly",
false);
obj.style.backgroundColor
=
"#ffffff";
}
function
changebutton1()
{
document.getElementById('btn1').value
=
'继续添加';
}
function
changebutton2()
{
document.getElementById('btn1').value
=
'提交';
}
应用:可将上诉代码中的文字替换,实现其它类型的循环执行。
请问这个JS代码怎么循环执行?
fragmentImg(fragmentConfig);
改为
setInterval("fragmentImg(fragmentConfig)",2000);
2000是毫秒,即2秒循环执行一次