2010-08-03 27 views
0

我正在研究ASP.Net網站的一些基本表單驗證樣式。 我需要選擇所有可見的span元素,並將css樣式添加到另一個元素。 (只是爲了指示哪些輸入字段無效):在Internet Explorer中不可用的可見選擇器

下面的代碼在FF和Safari中的作用就像一個魅力,但在IE中失敗。我將問題縮小到:可見選擇器。這裏是jQuery代碼。

重要提示:生產現場正在運行的jQuery 1.3.1有對所做的更改:可見選擇在1.3.2 release notes

$('span.inputError:visible').each(function() { 
      $(this).parent().parent().prev('td').children('label').children('span').css('color','red'); 
     }); 

這裏的渲染HTML它適用於:

<table width="100%" cellspacing="0" cellpadding="3" border="0"> 
      <tbody> 
      <tr> 
       <td valign="top" style="text-align: right;" class="address_labels"> 
        <label><span>*</span> First Name: </label> 
       </td> 
       <td> 
        <span id="ctl00_CMain_txtFirstName_wrapper"><input type="text" style="width: 190px;" invalidstyle="inputError" class="radEnabledCss Input" name="ctl00_CMain_txtFirstName_text" id="ctl00_CMain_txtFirstName_text" size="20" value=" zdogg"><input type="text" value=" zdogg" style="border: 0pt none ; margin: -18px 0pt 0pt; padding: 0pt; overflow: hidden; visibility: hidden; width: 1px; height: 1px;" name="ctl00$CMain$txtFirstName" id="ctl00_CMain_txtFirstName"><input type="hidden" name="ctl00_CMain_txtFirstName_ClientState" id="ctl00_CMain_txtFirstName_ClientState" autocomplete="off"></span> 
        <div> 
          <span style="color: Red; display: none;" class="inputError" id="ctl00_CMain_valFirstName">First name is required</span> 
         </div>   
       </td> 
      </tr> 

     </tbody></table> 
+0

看到我的「無答案」我想我們需要更多的信息在這裏。 – 2010-08-03 18:16:32

回答

0

我把你的代碼放在:http://jsfiddle.net/BZRWF/1/ 使用jquery 1.2.6,它似乎工作(我添加了一個按鈕來點擊實例化事件)。我在兼容模式下使用IE8進行測試,沒有任何問題。

我也在1.3.2和1.4.2中測試過,它在那裏也能正常工作。

相關問題