DOM元素可以包含空格的ID吗? [英] Can a DOM element have an ID that contains a space?

查看:127
本文介绍了DOM元素可以包含空格的ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是这样,你如何选择使用jQuery?即, $(#ab)查找节点内所有< b> 节点 id = a

解决方案

根据基本类型的HTML 4.0规范




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


即使空格有效,具有空格的id属性将被jQuery解释为祖先后裔选择器与当前选择器语法。


And if so, how do you select on with jQuery? I.e., $("#a b") looks for all <b> nodes within the node with id=a.

解决方案

According to the HTML 4.0 specification for basic types:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

And even if spaces were valid, an id attribute with spaces would be interpreted by jQuery as an ancestor descendant selector with the current selector syntax.

这篇关于DOM元素可以包含空格的ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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