使用jQuery突出显示效果时 window.name 的奇怪问题

Strange issue on window.name when using jQuery highlight effect

本文关键字:name window 问题 jQuery 显示 使用      更新时间:2023-09-26

我经常对一些表数据(td)单元格使用jQuery突出显示效果。我刚刚意识到,当我使用这个效果时,高光效果完成后,"data-ec"值的 window.name 值会神奇地发生变化。此行为给我带来了一些问题,因为我需要检查以前设置 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中则不然。

提前非常感谢。

我用"动画"函数替换"效果"函数来解决。

我使用了以下函数:

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