在 html 代码中,我使用代码 <input type = "text" id = "abc@def.com">
来获取文本,现在它需要获取在文本字段中输入的值。我正在使用 jquery 来做到这一点:
$( document ).ready( function() {
$( ".bid" ).click( function() {
idVal = this.id
bidID = "#" + idVal + "bid"
spanID = "#" + idVal + "cbid"
bidValue = $(bidID).val();
alert(idVal)
alert(bidID)
alert(bidValue) //this alert says undefined
$( spanID ).html( ' ' ).load( '{% url online_machines %}?id=' + idVal + '&bidvalue=' + bidValue);
});
});
通过这样做,我得到了未定义的值错误。我试图从 id 中删除特殊字符以获取其值。但我需要带有特殊字符的 id。如何使用 jquery 获取它的值?
原文由 big 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试转义它:
http://api.jquery.com/category/selectors/ 的第一段