将div添加到IE

时间:2013-05-04 16:47:54

标签: javascript internet-explorer html append

此代码在IE中不起作用,为什么不呢?

$('body').append('<div id="iedialog"><h2 class="dialog-header">Alert!</h2><div class="dialog-container"><center>It looks like you are using Internet Explorer! Please switch to another browser to use all our Designer features. We recommend Firefox (<a href="www.firefox.com">www.firefox.com</a>) and Google Chrome (<a href="www.google.com/chrome">www.google.com/chrome</a>) for an overall better internet experience.<br /><br /><input type="button" value="OK" id="okiedialog"></center>');

然而,如果我在控制台中复制并粘贴这些确切的代码,它就可以工作。

1 个答案:

答案 0 :(得分:1)

我会指出你的代码有几个问题。附加的标记无效。可以看出它何时被分解。

1)您的代码未正确关闭

<div id="iedialog">
    <h2 class="dialog-header">Alert!</h2>
    <div class="dialog-container">
        <center>
            It looks like you are using Internet Explorer! Please switch to another browser to use all our Designer features. We recommend Firefox (<a href="www.firefox.com">www.firefox.com</a>) and Google Chrome 
            (
                <a href="www.google.com/chrome">www.google.com/chrome</a>
            ) 
            for an overall better internet experience.
            <br />
            <br />
            <input type="button" value="OK" id="okiedialog">
        </center>

您的input代码未关闭,您的div代表dialog-container和代码iedialog未关闭。

1)您的标记使用已弃用的标记center。摆脱它,然后再试一次。