如何使用jquery获取HTML标记的text属性值 [英] How do I get value of text attribute of HTML tag using jquery

查看:71
本文介绍了如何使用jquery获取HTML标记的text属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的HTML标签



< input id =textbox1type =texttext = 12345 value =xyz>



i需要12345,文本属性值。



我尝试了什么:



i尝试了这个$(#textbox1)。prop('text');



给出未定义的

here is my HTML tag

<input id="textbox1" type="text" text="12345" value="xyz">

i need 12345, value of text attribute.

What I have tried:

i tried this $("#textbox1").prop('text');

Its giving undefined

推荐答案

(#textbox1)。prop('text');



给出undefined
("#textbox1").prop('text');

Its giving undefined


使用 .attr () [ ^ ]



use .attr()[^]

var text =


#textbox1')。attr(' 文本');
alert(text);
('#textbox1').attr('text'); alert(text);










来自官方网站:

在特定情况下,属性和属性之间的区别很重要。在jQuery 1.6之前,.attr()方法在检索某些属性时有时会考虑属性值,这可能会导致行为不一致。从jQuery 1.6开始,.prop()方法提供了一种显式检索属性值的方法,而.attr()检索属性。

The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.


这篇关于如何使用jquery获取HTML标记的text属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆