2012-12-30 70 views
4

這是代碼和jsfiddle鏈接。我嘗試了.text和.html兩個函數。但兩者都不適用於IE8。任何人都可以爲我提供IE的解決方案嗎? (我用Google搜索,人們似乎有類似那樣的問題,但不能得到解決)謝謝Jquery - .text(),.html()無法在IE8上工作

http://jsfiddle.net/3eaGL/

<div class="controls">  
      <div class="btn-group" data-toggle="buttons-radio"> 
       <input name="MySecurity[my_education]" id="MySecurity_my_education" type="hidden" value="0" />        
       <button type="button" class="btn" value="2" display="Private">P</button> 
       <button type="button" class="btn" value="1" display="Friends">F</button> 
       <button type="button" class="btn" value="0" display="All (Public)">A</button> 
      </div> 
      <text class="mySecurityDisplay"></text> 
     </div> 




$("button[display]").bind('click', function(){ 
        var buttonValue=this.value; 
        $(this).siblings("input[type=hidden]").val(buttonValue); 
        $(this).parent().next().text($(this).attr('display')); 
       }); 
+0

是否有任何錯誤發生?或者它不起作用? –

+0

謝謝馬漢。這是我收到的錯誤消息:對方法或屬性訪問的意外調用。 – Bujji

回答

4

你的問題是<text>標籤。這不是一個有效的HTML標籤。版本9下面的IE以這種方式解釋未知標籤:<text class="mySecurityDisplay"></text>將變爲<text class="mySecurityDisplay"/><text/>,因此您不能在其中插入任何內容。

只要寫<div class="mySecurityDisplay"></div>,這將工作。

+0

爲什麼downvote? thanx的有用的意見-..- – bukart

+0

我想知道爲什麼有人下來投票你的答案:(但不是那個不是我 – Bujji

+0

有人可能改善自己的答案...幼兒園 – bukart

0
  1. 檢查您是否有有效的html,可能存在不匹配的標籤。

  2. 嘗試使用append代替html方法。

+0

感謝您的回答 – Bujji

7

的問題是這樣的:

<text class="mySecurityDisplay"></text> 

IE8不會呈現未知的標籤,因此jQuery的不會選擇你的元素,這個問題是不相關的htmltext方法。改用一個有效的標籤,你的代碼就可以工作。

+0

謝謝。幫我 – Bujji

1

好吧,我得到它的工作的問題是<text>元素

http://jsfiddle.net/3eaGL/7/

Jquery的創建的實例對象選擇<text>元素之後,但因爲它不是一個有效的HTML標籤,jQuery對象將不會返回任何你的處置方法。

它就像你試圖做一個val()<span>元素,但只對html表單元素有效。

+0

是的,這個工作。謝謝 – Bujji