第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

怎么讓我的p2自動在one和two這兩個樣式之間自動跳轉(zhuǎn)呢,有不有大神可以幫個忙,謝謝

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>className屬性</title>

<style>

? ? body{ font-size:16px;}

? ? .one{

border:10px solid #cab;

width:230px;

height:50px;

background:#ccc;

color:red;

? ? }

.two{

border:10px solid #ccc;

width:230px;

height:50px;

background:#9CF;

color:blue;

}

</style>

</head>

<body>

? ? <p id="p1" > JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

? ? <input type="button" value="添加樣式" onclick="add()"/>

<p id="p2" class="one">JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

? ? <input type="button" value="更改外觀" onclick="modify()"/>


<script type="text/javascript">

? ?function add(){

? ? ? var p1 = document.getElementById("p1");

? ? ? p1.className="one";

? ?}

? ?

? ?var p2 = document.getElementById("p2");

? ? ? p2.className="two";

? ? ? document.write("現(xiàn)在的樣式ID是:"+p2.className);

? ?function modify(){


? ? ? ? if(p2.className=="one")

? ? ? ? {

? ? ? ? ? ? p2.className="two"

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? p2.className="one"

? ? ? ? }

? ? }

? ??

? ?

</script>

</body>

</html>


正在回答

3 回答

自動切換的話需要使用到定時器。setInterval(),js定時器相關(guān)知識可以網(wǎng)上搜索一下,good luck

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>className屬性</title>

<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="p1" > JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

? ? <input type="button" value="添加樣式" onclick="add()"/>

<p id="p2" class="one">JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

? ? <input type="button" value="更改外觀" onclick="modify()"/>

? ? <input type="button" value="自動切換" onclick="start()">

? ? <input type="button" value="停止" onclick="stop()"/>

? ??

<script type="text/javascript">

? ?function add(){

? ? ? var p1 = document.getElementById("p1");

? ? ? p1.className='one';

? ?}

? ?function modify(){

? ? ? var p2 = document.getElementById("p2");

? ? ? p2.className=p2.className==='two'?'one':'two';

? ?}

? ?var init;

? ?

? ?function start(){

? ? ? ?init = self.setInterval('modify()',1000);

? ?}

? ?

? ?function stop(){

? ? ? ?init = self.clearInterval(init);

? ?}

??

</script>

</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

qq_夜靜了_0 提問者

非常感謝!
2018-08-15 回復(fù) 有任何疑惑可以回復(fù)我~
#2

mihachen

我想問一下這個 p2.className=p2.className==='two'?'one':'two'; 這個是什么意思?
2018-09-07 回復(fù) 有任何疑惑可以回復(fù)我~
#3

面包與理想 回復(fù) mihachen

3元運(yùn)算符 p2.className 等于“two” ,執(zhí)行把“one”賦值給p2.className,反之把“two”賦值給p2.className
2018-09-12 回復(fù) 有任何疑惑可以回復(fù)我~
#4

慕妹602489

報錯了,star is not defind
2018-09-18 回復(fù) 有任何疑惑可以回復(fù)我~
查看1條回復(fù)

我想問一下這個

? ? ? p2.className=p2.className==='two'?'one':'two';

這個是什么意思?


0 回復(fù) 有任何疑惑可以回復(fù)我~

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>className屬性</title>

<style>

body{ font-size:16px;}

.one{

border:10px solid #cab;

width:230px;

height:50px;

background:#ccc;

color:red;

}

.two{

border:10px solid #ccc;

width:230px;

height:50px;

background:#9CF;

color:blue;

}

</style>

</head>

<body>

<p id="p1" > JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

<input type="button" value="添加樣式" onclick="add()"/>

<p id="p2" class="one">JavaScript使網(wǎng)頁顯示動態(tài)效果并實現(xiàn)與用戶交互功能。</p>

<input id="sh1" type="button" value="one" onclick="modify()"/>

<script type="text/javascript">

function add(){

var p1 = document.getElementById("p1");

p1.className="one";

}

var p2 = document.getElementById("p2");

var button = document.getElementById("button");

// ? p2.className="two";


// ? document.write("現(xiàn)在的樣式ID是:"+p2.className);

function modify(){

if(p2.className=="one")

{

p2.className="two";

document.getElementById("sh1").value="two";

}

else

{

p2.className="one";

document.getElementById("sh1").value="one";

}

}

</script>

</body>

</html>

樓主寫的已經(jīng)可以更換樣式了,我調(diào)整了一下button的問題

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

qq_夜靜了_0 提問者

你這個是自動的嗎? 為什么我這兒用了還是要不停的手動去點按鈕它才能替換呢
2018-08-04 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

怎么讓我的p2自動在one和two這兩個樣式之間自動跳轉(zhuǎn)呢,有不有大神可以幫個忙,謝謝

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號