JQuery获取属性值

$("#divid").text();  //获取id为divid下的文本内容

$("#divid").attr("name");  //获取id为divid标签的name的值

$("#divid").attr("name","zhangjiao");  //设置id为divid的标签的name属性值为“zhangjiao”

$("#divid").prop("name","zhangjiao");  //设置id为divid的标签的name属性值为“zhangjiao”

$("#divid").html();  //获取节点标签内容

$("#divid").val();  //获取id为divid的标签的value

$("#divid").prop("checked",false);  //设置id为divid的标签不可被选中,注意后面没有引号

document.getElementById("divid").setAttribute("style","color:red");//相当于$("#divid").css("color","red");

 

//待验证

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);

posted @ 2017-05-27 18:06  Index娇  阅读(607)  评论(0编辑  收藏  举报