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?

Customer and ServerCodeThey 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.