我有一個簡單的JavaScript,它將樣式添加到滑塊時,將顯示,但我想刪除下一個滑塊時的樣式,並在鼠標移除這兩種樣式。javascript添加樣式刪除樣式
這是我的javascript函數,它將style =「width:200px」添加到新滑塊並向舊的添加style =「width:200px」。
function test(){
var read = document.getElementById("slide-0") // how can i add here to read the incremented slide-0, slide-1, slide-2
.removeAttribute("style",0);
}
function noEffect(pOld,pNew){
if (pOld){
pOld.style.width='10px';
}
if (pNew){
pNew.style.width='200px'; //this style become on active slider.
}
}
滑塊HTML
<div class="slider" onMouseOver="test()">
<ul>
<li id="slide-0" class="slide" style="width: 10px"><img src="image.jpg"></li>
<li id="slide-1" class="slide" style="width: 200px"><img src="image.jpg"></li> <!-- this is active now -->
</ul>
</div>
正是我想要的是在鼠標懸停除去雙方的風格。
任何幫助表示讚賞。
id爲 「滑動0」 是重複的,ID不能重複。 '
' –是的,對不起,我複製粘貼,我現在修改。 – Dario
不錯。很高興你設法解決你的問題。 –