The problem that HTML does not support static Expando Elements

Source: Internet
Author: User

When using scripts to process a batch of pages in a unified manner, I want to obtain the document TITLE and custom attributes through the TITLE element of the processed page. These additional Attributes are added on the server through the Attributes set, but the running results are always far from what I expected, why is the custom attribute I write in the TITLE element always null?

The client and server code are:

ASPX:
<Title id = "title" runat = "server"> Query Info </title>
C #: protected HtmlGenericControl title;

Private void Page_Load (object sender, System. EventArgs e)
{
//...
Title. InnerHtml = "querying information ";
Title. Attributes ["icon"] = "QueryInfo.gif;
}
HTML:
<Title id = "title" icon = "QueryInfo.gif"> Query Information </title>
JavaScript:
Var iconPath = docucment. all. tags ('title') [0]. icon;
If (iconPath)
{
Var img = document. createElement ('img ');
Img. src = iconPath;
//...
}

The result is the icon that I want from the total topology, tracking JavaScript code, and finding that iconPath is always undefined. Look at the HTML code, which clearly shows the attribute value pair "icon =" QueryInfo.gif. Therefore, you can view outerHTML from the title object. outerHTML is actually: <title id = "title"> Query Information </title>. There is no icon attribute at all. It is no wonder that iconPath obtained by JavaScript is always undefined.

After careful investigation, we found that html elements differ in processing the expando attribute. There are two ways to add the expando attribute to an html element. One is the common dynamic method. The other is to use a script to add the expando attribute to an html element. The second is to use the static method, that is, to add the expando attribute in literal mode in html code. Examples:

Add the expando attribute dynamically: <span id = mySpan> this is a span element. </span>
<Script language = javascript>
MySpan. myAttri = 'attribute ';
</Script>
Add the expando attribute statically: <span id = mySpan myAttri = attribute> this is a span element. </span>
There is no difference between the two methods, but the element title only supports dynamic addition of the expando attribute, and does not support static addition of the expando attribute, this is why I started to get an error. What other html elements and titles do not support static addition of the expando attribute? In the 108 html elements, the following 10 elements do not support static addition of the expando attribute:
HTML, HEAD, TITLE, BODY, BASEFONT, FORM, HR, HR, TBODY, SCRIPT
However, dynamic addition of the expando attribute is supported by all html elements and dhtml objects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.