在我的JSP中,我使用自定义标记<showDateFormat/>
喜欢:
Date From:<showDateFormat/>
在我的common.js文件中我有
function addDateFormatInfo(){
var dateFormatHolder = document.getElementsByTagName("showDateFormat");
if ( dateFormatHolder ){
for ( i = 0 ; i < dateFormatHolder.length; i++ ){
dateFormatHolder[i].innerHTML = '<div class="infoSmall" ><span>(mm/dd/yyyy)</span></div>';
}
}
}
因此,在我的页面中,只要使用showDateFormat
标记,就会显示(mm/dd/yyyy)
。它在FF中工作正常,但在IE中却没有。可能是什么问题?
答案 0 :(得分:5)
您需要先告诉IE有关该标记的信息。在调用addDateFormatInfo()
之前在某处添加此行:
document.createElement("showDateFormat");
IE现在将正确初始化元素 - 您可以像处理任何其他元素一样对待它。 Firefox会自动执行此操作。
这是源博客文章:
http://ajaxian.com/archives/getting-html-5-styles-in-ie-7
在IE7中支持createElement()
启动 - 虽然我在FF3.0.15中工作正常
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home | My Website</title>
</head>
<body>
<script type="text/javascript">
document.createElement("showDateFormat");
function addDateFormatInfo(){
var dateFormatHolder = document.getElementsByTagName("showDateFormat");
if ( dateFormatHolder ){
for ( i = 0 ; i < dateFormatHolder.length; i++ ){
dateFormatHolder[i].innerHTML = '<div class="infoSmall" ><span>(mm/dd/yyyy)</span></div>';
}
}
}
</script>
<div>
Date From:<showDateFormat/>
</div>
<div>
Date From:<showDateFormat/>
</div>
<div>
Date From:<showDateFormat/>
</div>
<div>
Date From:<showDateFormat/>
</div>
<p><input type="button" value="click me" onclick="addDateFormatInfo()" />
</p>
</body>
</html>
答案 1 :(得分:0)
请查看Internet Explorer中的自定义标记支持。
Windows Internet Explorer的支持 用于HTML页面上的自定义标记 要求定义名称空间 对于标签。否则,自定义标记 被视为未知标签时 文档被解析
http://msdn.microsoft.com/en-us/library/ms531076(VS.85).aspx
答案 2 :(得分:0)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:IETag>
而不是普通:
<showDateFormat/>
使用
<IETag:showDateFormat/>
cutom标签功能更强大,特别是在绑定到HTC行为时,但不幸的是它们仍然是IE特定的,尽管您可以设法使用JQUERY为所有浏览器编写代码,请在此处阅读更多内容: Using custom tags in IE