本文目錄一覽:
這段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秒循環執行一次
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/308752.html