0

Please Check below code In IE8:

 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
           <script language="javascript" type="text/javascript">
            function btnclick() {
                document.createElement("myTag");
                var testctrl = document.createElement("div");
                testctrl.innerHTML = " <myTag>hai</myTag>";
                document.getElementById("temp").appendChild(testctrl);
alert(testctrl.innerHTML);
            }
        </script>
        <style type="text/css">
        myTag
        {
            background-color:Blue;
            height:20px;
            width:100px;
        }
        </style>
    <title>

    </title></head>
    <body>
        <input type="button" id="tbtn" onclick="javascript:btnclick();return false;" value="ClickMe"/>
        <div id="temp" >
        </div>
    </body>
    </html>

i got value from myTag Like As :

**testctrl.innerHTML contain as Follow**

"hai</MYTAG>"

So how can i use in this code for IE? I Should be want the tags Like as not like as

4

2 回答 2

3

Try:

var mytag = document.createElement("myTag");
var testctrl = document.createElement("div");
mytag.innerHTML = "hai";
testctrl.appendChild(mytag);
document.body.appendChild(testctrl);
于 2012-10-20T08:49:21.733 回答
0

Using custom tags is always kind of wired because browser differ in handling custom tags. If you are working with xhtml and xhtml headers you should add your namespace to the html and the element, but mixing custom tags with xhtml tags is something I would not do. I once used custom namespace attributes what did a good job but therefor you should use the html5 data attributes.

于 2012-10-20T08:48:59.173 回答