2013-05-04 64 views
0

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

$('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>'); 

然而,如果我复制并粘贴在控制台中的这个确切的代码,它的工作原理。

+3

也许你在创建body之前调用它? – 2013-05-04 16:50:01

+0

你什么时候运行上面的代码? – techfoobar 2013-05-04 16:50:53

+1

作者golly,你是对的!我把这个代码放在body标签之前。现在正在工作。你想把它作为答案,所以我可以选择它吗? – user961627 2013-05-04 16:51:45

回答

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 s的dialog-container class和id iedialog未关闭。

1)您的标记使用了不赞成使用的标记center。摆脱它,然后再试一次。

+0

感谢您的注意!我会解决这个问题。但主要的问题是我在body标签前面有这个脚本。 – user961627 2013-05-04 16:56:31