html标签ID中的特殊字符

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( '&nbsp;' ).load( '{% url online_machines %}?id=' + idVal + '&bidvalue=' + bidValue);

});

});

通过这样做我得到未定义的值错误。我试图从ID中删除特殊字符以获取其值。但是我需要带特殊字符的ID。如何使用jquery获得其值?

回答:

尝试转义:

$('#abc\\@def.com').val();

以上是 html标签ID中的特殊字符 的全部内容, 来源链接: utcz.com/qa/410576.html

回到顶部