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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

如何獲得元素的屬性

?我用下面的方法為什么不能獲得p3的屬性color,height,width??

function concel(){
???????? var p1=document.getElementById("p1");
???????? var p3=document.getElementById("p3");
???????? p1.style.color=p3.style.color.nodeValue;
???????? p1.style.width=p3.style.width.nodeValue;
???????? p1.style.height=p3.style.height.nodeValue;
???????? p1.style.display="block";
???? }

?

正在回答

2 回答

直接使用style屬性無法訪問到內(nèi)嵌(寫在head標(biāo)簽中的),外部(寫在css文件中的)的css樣式,只能訪問內(nèi)聯(lián)樣式(寫在標(biāo)簽中的)的css樣式

很用心在回答,滿意的話給個(gè)采納表示支持,感謝!


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

可能有兩個(gè)原因?qū)е履悴荒苷_取消設(shè)置屬性的問題,導(dǎo)致你懷疑可能是沒有獲取到屬性。

  1. 你代碼里面是否設(shè)置了唯一的id

  2. 你獲取到的屬性已經(jīng)被修改過,所以取消時(shí)再次賦值也取不到最初的值了。應(yīng)該要保存最初屬性。

    貼一下驗(yàn)證通過的代碼,可以參考下:


  3. var con=document.getElementById("con");

  4. var txt=document.getElementById("txt");

  5. var conColor=con.style.color;

  6. var conHeight=con.style.height;

  7. var conWidth=con.style.width;

  8. var txtIsShow=con.style.display;


  9. ? ? function changeColor(){

  10. ? ? ? ? con.style.color="pink";

  11. ? ? }


  12. //定義"改變寬高"的函數(shù)

  13. ? ? function changeWH(){

  14. ? ? ? ? con.style.height="500";

  15. ? ? ? ? con.style.width="300";


  16. ? ? }


  17. //定義"隱藏內(nèi)容"的函數(shù)

  18. ? ? function hideTxt(){

  19. ? ? ? ? txt.style.display="none";

  20. ? ? }


  21. //定義"顯示內(nèi)容"的函數(shù)

  22. function showTxt(){

  23. ? ? txt.style.display="block";

  24. }


  25. //定義"取消設(shè)置"的函數(shù)

  26. function cancel(){

  27. ? ? ?con.style.color=conColor;

  28. ? ? ? con.style.height=conHeight;

  29. ? ? ? ? con.style.width=conWidth;

  30. ? ? ? ? ? txt.style.display=txtIsShow;

  31. }

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

舉報(bào)

0/150
提交
取消

如何獲得元素的屬性

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

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

幫助反饋 APP下載

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

公眾號(hào)

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