js怎么创建属性节点,设置属性值,向元素添加属性节点?

js怎么创建属性节点,设置属性值,向元素添加属性节点?,第1张

这写的有点太乱了吧,js和jQuery结合?!!?

js这样写一句话就可以

document.getElementsByTagName("input")[0].setAttribute("disabled", "disabled")

jQuery这样一句话就可以

$("input").attr("disabled","disabled")

jQuery attr() 方法设置或返回被选元素属性值。

获取属性值语法

$(selector).attr(attribute)

参数描述

attribute规定要获取其值的属性。

设置属性

设置被选元素的属性和值。

语法

$(selector).attr(attribute,value)

参数 描述

attribute规定属性的名称。

value 规定属性的值。

var h1 = document.getElementByTagName('h1')//获取dom

h1.setAttribute('align','center')//添加属性

var value= h1.getAttribute('align')//读取属性值

<script language="javascript" type="text/javascript">

function fcreatenode()

{

var op=document.createElement("div")

//var oa=document.createAttribute("style")

//op.attributes.setNamedItem(oa)

//op.setAttribute("style","color:#555555")

op.style.color = "#555555" //style 是一个已存在的属性

//var otext=document.createTextNode("hello world")

//op.appendChild(otext)

op.innerHTML = "hello world"

document.getElementById("div1").appendChild(op)

}

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11785099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存