控制類(lèi)名如何讓按鈕循環(huán)效果?
現(xiàn)在點(diǎn)擊按鈕,可以添加.two樣式?如果想再點(diǎn)擊一次按鈕,恢復(fù).one樣式。循環(huán)往復(fù),不知道該添加什么語(yǔ)句??
<style>
? ? body{ font-size:16px;}
? ? .one{
border:1px solid #eee;
width:230px;
height:50px;
background:#ccc;
color:red;?}
.two{
border:1px solid #ccc;
width:230px;
height:50px;
background:#9CF;
color:blue;}
</style>
</head>
<body>
? ? <p id="p2" class="one">JavaScript使網(wǎng)頁(yè)顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
? ? <input type="button" value="更改外觀" onclick="modify()"/>
<script> ? ? ??
? function modify(){
? ? ?var p2 = document.getElementById("p2");
? ? ?p2.className="two";?}
</script>
2014-12-12
if("one"==p2.className)
? ? ? ? ? {
? ? ? ?p2.className="two";
? ? ? ? ??
? ? ? ? ? }else{p2.className="one";}
2014-11-26
本人菜鳥(niǎo),弱弱的寫(xiě)個(gè)想法function add(){
? ? ?var p1 = document.getElementById("p1");
? ? ? ? ? if(p1.className=="one"){
? ? ? ? ? ? ? p1.className="two";
? ? ? ? ? }else{
? ? ? ? ? ? ? p1.className="one";
? ? ? ? ? } ?
? }
2014-11-19
你可以參考下,自己用其他的方式寫(xiě)寫(xiě)試試