html标记的id中的特殊字符 [英] special characters in id of html tags

查看:184
本文介绍了html标记的id中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在html代码中,我使用代码
< input type =textid =abc@def.com> 来获取文本
现在需要获得它在文本字段中输入的值。

In html code I am using code <input type = "text" id = "abc@def.com"> to get text now it need to get its value which is entered in text field. I am using jquery to do that:

$( 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获取其值?

By doing this i get the value error undefined. I tried to remove special characters from the id to get its value. But I need the id with special characters. How can I get its value using jquery ?

推荐答案

尝试转义它:

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

第一段 http://api.jquery.com/category/selectors/

这篇关于html标记的id中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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