Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更改容器的值?_Javascript_Jquery - Fatal编程技术网

Javascript 如何更改容器的值?

Javascript 如何更改容器的值?,javascript,jquery,Javascript,Jquery,我有以下代码: if (json.result=='OK') { message="Your correction has been added successfully"; $("#ShoppingCartView.custom_terms_n_conditions/24").empty(); $("#ShoppingCartView.custom_terms_n_conditions/24").html('123

我有以下代码:

if (json.result=='OK') {
              message="Your correction has been added successfully";
             $("#ShoppingCartView.custom_terms_n_conditions/24").empty();
             $("#ShoppingCartView.custom_terms_n_conditions/24").html('123');
}
alert(message);
问题是:我可以看到带有消息的警报,但是id=“ShoppingCartView.custom\u terms\u n\u conditions/24”的元素不会更改其值!这个元素确实存在,我不明白为什么。请帮帮我

您必须使用两个斜杠来标记
/
字符。另外,
.html
将覆盖,因此已为空:

$("#ShoppingCartView\\.custom_terms_n_conditions\\/24").html("123");

这是工作代码,您只需使用
\\

if (json.result=='OK') {
              message="Your correction has been added successfully";
 $("#ShoppingCartView.custom_terms_n_conditions\\/24").html('123');
}
alert(message);

您也不需要调用empty()@JonTaylor不,完全无效。在jquery中,我认为这会调用一个换行符。对于引用id,应该匹配
[a-Za-z][a-Za-z0-9:.]*
@Jon Taylor:HTML5 allows.@pimvdb尽管在HTML 5中,正如您指出的,使用它可能是安全的,我不认为使用它是安全的,因为在我对OP的评论中提到的完全跨浏览器兼容的idAs
/
不是html id中的有效字符。我认为
自定义术语\u n\u条件/24
是一个类名。@未定义:OP使用
id=“…”
@pimvdb尽管在HTML 5中,正如您指出的,使用它可能是安全的,但我认为作为完全兼容跨浏览器的id使用它还不安全。谢谢,它可以工作。那么,请告诉我,我如何以编程方式转义字符串?谢谢。但是我怎样才能通过编程来逃避呢?