我是 jquery 的初学者。
我试过这个https://jsfiddle.net/0xLqhufd/2/
<body>
<div>
<input type="text" person="firstName" value="John">
<input type="text" person="birthDate" value="September 1st, 2000">
</div>
</body>
但我的警报中只有空白:
$('input[person]').each(function(index) {
alert(index + ': ' + $(this).text());
}
);
最佳答案
正如 jQuery 文档中所述...
The .text() method cannot be used on form inputs or scripts
使用 .val() 代替。
$('input[person]').each(function(index) {
alert(index + ': ' + $(this).val());
}
);
<强> Working Demo
关于javascript - jquery中如何通过自定义属性获取输入字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401832/