innerHTML在FF中工作但在IE中没有! [英] innerHTML working in FF but not in IE!
问题描述
在我的JSP中,我使用自定义标记< showDateFormat />
like:
In my JSP i am using a custom tag <showDateFormat/>
like:
Date From:<showDateFormat/>
在我的common.js文件中我有
and in my common.js file i am having
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中却没有。可能是什么问题?
so in my page wherever there is showDateFormat
tag is used, it will display (mm/dd/yyyy)
. It is working fine in FF, but not in IE. what could be the problem?
推荐答案
您需要先告诉IE有关该标签的信息。在调用 addDateFormatInfo()
之前在某处添加此行:
You need to tell IE about the tag first. Add this line somewhere before calling addDateFormatInfo()
:
document.createElement("showDateFormat");
IE现在可以正确初始化元素 - 您可以像对待任何其他元素一样对待它。 Firefox会自动执行此操作。
IE will now initialize the element correctly - you can treat it just like any other element. Firefox does this automatically.
以下是源博客帖子:
http://ajaxian.com/archives/getting-html-5-styles-in-ie-7
支持 createElement()
在IE7中启动 - 虽然我在FF3.0.15中工作正常/ p>
完整示例
Support for createElement()
starts in IE7 - though I works fine in 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>
这篇关于innerHTML在FF中工作但在IE中没有!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!