I have the following html code:

我有以下HTML代码:

   <div class="/temp">asdf</div>
   <input type="button" class="hide_message_button" value="Hide">

And the jQuery for it is something like this:

而jQuery就是这样的:

$('.hide_message_button').click(function(){
   var bool = $('./temp').is(':hidden');
   if(bool){
      $('./temp').show();
      $(this).val('Hide');
   }
   else {
      $('./temp').hide();
      $(this).val('Show');
   }
});

Well all I am trying to do is show or hide the div on button click. However, I get the following error:

好吧,我要做的就是在按钮点击时显示或隐藏div。但是,我收到以下错误:

Uncaught Error: Syntax error, unrecognized expression: ./temp 

Works fine when the class name is just "temp". Unfortunately, the class name is prefixed with / and I would not like to change it. How do I resolve the error?

当类名只是“临时”时工作正常。不幸的是,类名前缀为/,我不想改变它。我该如何解决这个错误?

3 个解决方案

#1


2

You need to escape the meta-characters.

你需要逃避元字符。

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\

要使用任何元字符(例如!“#$%&'()* +,。/:; <=>?@ [] ^`{|}〜)作为名称的文字部分,必须使用两个反斜杠进行转义:\\

$('.\\/temp').is(':hidden');

更多相关文章

  1. [求助]如何用JQuery来实现Ctrl+Space完成输入特定字符提示的自动
  2. 在线请教调用Jquery错误:TypeError: a is undefined 的错误原因
  3. 在发出xml Ajax请求时获取错误412
  4. 如何设置请求标头字符串[重复]
  5. Internet Explorer导致无效的真实性令牌错误
  6. DataTables警告:table id = DataTables_Table_0 - Ajax错误。有
  7. 如何在使用jquery验证和自定义错误放置时清除错误
  8. Ajax调用php脚本返回404错误
  9. Jquery验证插件,获取错误字符串

随机推荐

  1. HTML5绘图之Canvas标签 绘制坐标轴
  2. java 如何获取动态网页内容,返回字符串
  3. 我应该如何显示包含XML数据源的表?
  4. JavaScript系列----面向对象的JavaScript
  5. 在javascript中过滤对象对象(过滤还是减少
  6. 将div停靠在窗口左侧并再次单击原始位置
  7. 如何使用django从静态文件加载静态文件?
  8. 前端优化方案-JavaScript 优化方案
  9. HTML5练习之简陋版我画你猜(一)
  10. 有一个简单但有用的jquery.JsPlumb示例吗