HTML类并与$或非字母数字字符标识 [英] HTML classes and IDs with with $ or non alpha numeric characters

查看:320
本文介绍了HTML类并与$或非字母数字字符标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待在上XHTML DOCTYPE一​​些网站的code和从我所看到的框架是ASP.net。在HTML的ID在有$。

I'm looking at some site code on an XHTML doctype and from what I'm seeing the framework is ASP.net. The IDs in the HTML has a "$" in there.

例如:

<img id="$ct100templateContent$SectionPanel1$ctl01$ctl02ctl00_templateContent_SectionPanel1_ctl01_ct999img" src="this.jpg"/>

从一个W3C语义点$是不是在一个ID或类有效。 ID和班级只能包含在XHTML文档类型字母数字字符。

From a W3C semantic point of view the "$" is not valid in an ID or Class. IDs and classes can only contain alpha numeric characters in an XHTML doctype.

是的$一个ASP.net命名约定引用Web控件或模板项目?

Is the the "$" a ASP.net naming convention referencing a web control or template item?

推荐答案

我有点困惑如何/为何你看到美元符号在标识

I'm a little confused how/why you're seeing dollar signs in the id.

在渲染一个Web控件到标记,ASP.NET生成元素的 ID 名称属性基础上, Web控件的 ID 属性及其在控制层级位置。总之,某些控件 - 比如模板控件或重复控制 - 作为的命名容器的。这样的控制 ID 属性值pfixed自己内心的控制$ P $'确定何时 ID 属性值 ID 名称属性。

When rendering a Web control into markup, ASP.NET generates the element's id and name attributes based on the Web control's ID property and its location in the control hierarchy. In short, certain controls - such as templated controls or repeating controls - act as naming containers. Such controls' ID property values are prefixed to their inner controls' ID property values when determining the id and name attributes.

例如,请考虑以下控制层次:

For example, consider the following control hierarchy:

在这里,母版页( ctl00 )和的ContentPlaceHolder(日程地址搜索Maincontent )控件命名容器。在年龄 TextBox Web控件将的渲染 ID clt00_MainContent_Age - 即它自己的服务器-side ID 属性值$ p $其命名容器的祖先 ID`值pfixed。

Here, the Master Page (ctl00) and ContentPlaceHolder (MainContent) controls are naming containers. The Age TextBox Web control will have a rendered id of clt00_MainContent_Age - namely, its own server-sideIDproperty value prefixed with theID` values of its naming container ancestors.

但需要注意的是如何呈现的 ID 被分隔每个命名容器点的用下划线。这是ASP.NET的默认功能,所以我很困惑,为什么你看到的 ID 属性美元符号。 (在制定名称属性,ASP.NET每个命名容器点一个美元符号分隔,但制定 ID时,它不应该使用$ 属性值。)

But note how the rendered id is separating each naming container spot with an underscore. This is the default functionality in ASP.NET, so I am perplexed as to why you are seeing dollar signs in the id attribute. (When formulating the name attribute, ASP.NET separates each naming container spot with a dollar sign, but it shouldn't use $ when formulating the id attribute value.)

什么版本的ASP.NET您使用的是?你在做什么...怪异?像使用自定义的控制和重写基控制类的<​​code> IdSeparator 属性?如果您在使用ASP.NET 4,你的设置(无论是有意还是无意的)控制的的ClientIDMode 属性?

What version of ASP.NET are you using? Are you doing anything... weird? Like using custom controls and overriding the base Control class's IdSeparator property? If you are using ASP.NET 4, are you setting (either intentionally or unintentionally) the control's ClientIDMode property?

这篇关于HTML类并与$或非字母数字字符标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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