Javascript 使用jquery访问文本输入属性
我有以下代码:Javascript 使用jquery访问文本输入属性,javascript,jquery,Javascript,Jquery,我有以下代码: $('.centering').click(function (e) { $(".thVal").replaceWith(function () { console.log(this); return this.value; }); $('.editFields').hide(); }); 这将提供以下输出: <input class="thVal" width="2" type="text" modelbind=
$('.centering').click(function (e) {
$(".thVal").replaceWith(function () {
console.log(this);
return this.value;
});
$('.editFields').hide();
});
这将提供以下输出:
<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson_Name" value="Test Oil AB">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson.PrimaryAddress_StreetAddress" value="Testgatan 1">
5505094091
<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson_PrimaryAddress_ZipCode" value="50010">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="x => x_LicenseHolder_LegalPerson_PrimaryAddress_HomeTown" value="Växjö Sverige">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="" value="0730730037">
5505094091(拉德256)
5505094091
5505094091(拉德256)
5505094091(拉德256)
当我写入console.log(this.value)
时,将显示输入值。但是我想访问modelbind属性的值,当我编写console.log(this.modelbind)
时,我只是没有定义
如何访问该值?您可以使用 如果您使用console.log($(this.attr)(“modelbind”)代码>
console.log($(this).attr("modelbind"))