Marydon20170307

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("要移除的属性名");

 

 相关推荐:

 

分类:

技术点:

相关文章:

  • 2021-09-18
  • 2021-11-09
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-12-27
  • 2021-08-25
猜你喜欢
  • 2021-12-17
  • 2021-12-27
  • 2022-12-23
  • 2021-12-27
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案