Home  >  Article  >  Web Front-end  >  Problem that static Expando elements are not supported in HTML_javascript skills

Problem that static Expando elements are not supported in HTML_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:17:45952browse

When using a script to process a batch of pages, I hope to get the title of the document and some of my custom attributes through the TITLE element of the page being processed. I added these additional attributes through the Attributes collection on the server side, but the running results are always far from my expectations. Why do the custom attributes I write in the TITLE element always have null values?

The client and server side codes are:

ASPX:

Query Info
C#: protected HtmlGenericControl title;

private void Page_Load(object sender, System.EventArgs e)
{
// ...
title.InnerHtml = "Query Information";
title.Attributes["icon"] = "QueryInfo. gif;
}
HTML:
Query information
JavaScript:
var iconPath = document.all.tags('TITLE')[0].icon;
if ( iconPath )
{
var img = document.createElement('IMG');
img.src = iconPath;
// ...
}

The result is that the icon I want is never displayed. I trace the JavaScript code and find that the iconPath is always undefined. Looking at the HTML code, there is clearly an attribute value pair of icon="QueryInfo.gif", so I retrieve it from the title object. Check outerHTML, outerHTML is actually: Query information. There is no icon attribute at all. No wonder the iconPath obtained by JavaScript is always undefined. After careful inspection, I found that it is an html element. There are differences in processing the expando attribute. There are two ways to add the expando attribute to the html element. One is the commonly used dynamic method; the other is to use the static method; that is, in the html code. Add the expando attribute in literal mode. Examples are as follows:

Dynamically add the expando attribute:
this is a span element.

Static add the expando attribute:
this is a span element. Originally there is basically no difference between the two writing methods, but the element title only supports dynamically adding the expando attribute, but does not support statically adding the expando attribute. This is why I started There will be reasons for errors. So what about those html elements that, like title, do not support static addition of the expando attribute? Among the 108 html elements, the following 10 elements do not support adding the expando attribute statically:
HTML, HEAD, TITLE, BODY, BASEFONT, FORM, HR, HR, TBODY, SCRIPT
However, adding the expando attribute dynamically, All html elements and dhtml objects are supported.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn