【问题标题】:Is it allowed to use '/' within the value of the id of a html-element [duplicate]是否允许在 html 元素的 id 值中使用“/”[重复]
【发布时间】:2011-08-18 21:57:22
【问题描述】:

可能重复:
What are valid values for the id attribute in HTML?

嗨, 我正在努力使用 jQuery UI 选项卡和所需的 id。 举个例子吧:

<div id="tabs">
  <ul>
    <li><a href="#messages/pn1">Link</a></li>
    <li><a href="#messages/pn2">Link</a></li>
  </ul>
  <div id="messages/pn1"></div>
  <div id="messages/pn2"></div>
</div>

现在,当我单击第二个选项卡时,我得到一个异常,例如“jQuery UI 选项卡:不匹配的片段标识符”。 是否允许在 id 中使用斜杠?

【问题讨论】:

  • 好的解决了。那是我需要的:如果您希望使用任何元字符(例如 !"#$%&'()*+,./:;?@[]^`{|}~ )作为名称的文字部分,您必须使用两个反斜杠转义字符:\\。例如,如果您有一个 id="foo.bar" 的元素,您可以使用选择器 $("#foo\\.酒吧”)。来自api.jquery.com/category/selectors

标签: jquery user-interface tabs


【解决方案1】:

对不起。 HTML 规范另有说明。

ID 和 NAME 标记必须以字母 ([A-Za-z]) 开头,后跟任意数量的字母、数字 ([0-9])、连字符 ("-")、下划线 (" _")、冒号 (":") 和句点 (".")。

http://www.w3.org/TR/html40/types.html#type-name

【讨论】:

    【解决方案2】:

    这是不允许的。看看here

    【讨论】:

      猜你喜欢
      • 2018-06-22
      • 2010-09-12
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      相关资源
      最近更新 更多