html中text的value值,js中的innerText、innerHTML、属性值、value与jQuery中的text()、html()、属性值、val()总结...

js与jQuery获取text、html、属性值、value的方法是不一样的。

js与jQuery,text与innerText获取(中为结果)

html:这是段落中的 粗体 文本。

jQuery显示text

jQuery显示 innerTEXT

js显示 innerTEXT

js:

$("#btn10").click(function(){

alert("Text: " + $("#test").text());

});

$("#btn11").click(function(){

alert("Text: " + $("#test").innerText);

});

$("#btn12").click(function(){

alert("Text: " + document.getElementById("test").id);

});

js与jQuery,html与innerHTML获取

html:这是段落中的 粗体 文本。

jQuery显示 HTML

jQuery显示 innerHTML

js显示 innerHTML

js:

$("#btn20").click(function(){

alert("HTML: " + $("#test").html());

});

$("#btn21").click(function(){

alert("HTML: " + $("#test").innerHTML);

});

$("#btn22").click(function(){

alert("HTML: " + document.getElementById("test").innerHTML);

});

js与jQuery,属性值获取

html:js获取Id的属性值

jQuery获取Id的属性值

js:

$("#btn30").click(function(){

alert("id: " + document.getElementById("test").id);

});

$("#btn31").click(function(){

alert("id: " + $("#test").attr("id"));

});

js与jQuery,value获取

html:js获取input标签的value值

jQuery获取input标签的value值(val())

jQuery获取input标签的value值(attr("value"))

js:

$("#btn40").click(function(){

alert("value: " + document.getElementById("test1").value);

});

$("#btn41").click(function(){

alert("value: " + $("#test1").val());

});

$("#btn42").click(function(){

alert("value: " + $("#test1").attr("value"));

});

注意:jQuery中的val()方法只能用于input元素的value值获取

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值