js-取值&賦值-獲取某標簽某屬性的值


js 取值&賦值-獲取某標簽某屬性的值

CreateTime--2016年10月16日16:35:34

Author:Marydon

1.取值

//方法一
//自定義屬性必須用getAttribute()方法
    var iframeSrcAttr = document.getElementById("importJsp").getAttribute("src");
    獲取得到的值是:test.html
//方法二
    var iframeSrcAttr = document.getElementById("importJsp").src;
    獲取得到的值是:http://127.0.0.1:8020/demo/test.html
//方法三
    var iframeSrcAttr = document.getElementById("importJsp").attributes["src"].value;
    獲取得到的值是:test.html

2.改變已存在屬性的屬性值

//方法一
document.getElementById("importJsp").setAttribute("src","#");
//iframe標簽的src屬性值已更改為"#"
console.log(document.getElementById("importJsp").getAttribute("src"));
//方法二
document.getElementById("importJsp").attributes["src"].value="#";                    
//iframe標簽的src屬性值已更改為"#"
console.log(document.getElementById("importJsp").getAttribute("src"));

  更改src沒有用,只能將iframe標簽全部替換掉才行

<iframe id='importJsp' width='700' height='500' frameborder='0' src='test.html'></iframe>

3.移除某一屬性
  removeAttribute("要移除的屬性名");

 

 相關推薦:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM