2013-10-14 45 views
0

我經常在某些表格數據(td)單元格上使用jQuery突出顯示效果。 我剛剛意識到,當我使用這種效果時,高亮效果完成後,window.name值在「data-ec」值中奇蹟般地改變。 這種行爲給我一些問題,因爲我需要檢查我以前設置的window.name。使用jQuery突出顯示效果時window.name的奇怪問題

我使用的代碼如下:

<html> 
<head> 
    <script src='jquery-1.6.min.js' type="text/javascript"></script> 
    <script src='jquery-ui-1.8.12.custom.min.js' type="text/javascript"></script> 

    <script type="text/javascript"> 

     function PlayIssue() { 
      //Set Window Name 
      window.name = 'myWindowName'; 
      // Get RIGHT window name 
      alert(window.name); // popup shows "myWindowName" as window name 

      //Play jQuery Effect on TD cell 
      var myCell = $("#TableID tr[id='row_ID'] td:nth-child(1)"); 
      myCell.effect("highlight", { color: '#FFA500' }, 8000); 

      //get WRONG window name 
      alert(window.name); // popup shows "data-ec" as window name 
     } 
    </script> 
</head> 
<body> 
    <table id="TableID" border="1"> 
     <tr id="row_ID"> 
      <td>cell 1</td> 
      <td>cell 2</td> 
     </tr> 
    </table> 

    <script type="text/javascript"> 

     //Call JS Function to play issue 
     PlayIssue(); 
    </script> 
</body> 
</html> 

你有這種行爲的任何想法? 這個問題發生在IE 9/10(只嘗試這些),但不是Firefox和Chrome。

非常感謝。

+0

你將不得不向我們展示一些標記來解釋「數據-EC」和「window.name」因爲沒有什麼在你的問題告訴我們什麼關於他們。 – Archer

+0

嗨弓箭手,感謝您的快速響應。我已經添加了代碼示例。再見 –

+0

即使通過政策我不能更新jQuery插件,我剛剛嘗試了版本jquery-ui-1.10.3.custom.min.js,但問題仍然是窗口的以下新名稱「data-ui -effects-opacity「而不是」data-ec「。 –

回答

0

我用'動畫'函數替換'效果'函數解決了。

我用下面的功能:

function flashColor(obj) { 
    if (obj.length) { 
     var originalColor = obj.css('backgroundColor'); 
     obj.animate({ backgroundColor: '#FFA500' }, 1000).delay(700).animate({ backgroundColor: originalColor }, 1000); 
    } 
}