HTML does not support static Expando elements _ javascript skills

Source: Internet
Author: User
HTML does not support static Expando elements. When you use 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 on 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:
Query Info
C #: protected HtmlGenericControl title;

Private void Page_Load (object sender, System. EventArgs e)
{
//...
Title. InnerHtml = "querying information ";
Title. Attributes ["icon"] = "QueryInfo.gif;
}
HTML:
Query Information
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. So you can view outerHTML from the title object. outerHTML is: Query Information. 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: this is a span element.

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.