2013-05-04 37 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