下面的代码正在删除它找到的第一个 div,而不是预期的 div。
jQuery
// Auto Remove PROMPT Notice Messages
(function($){
$(document).ready(function() {
$("[AutoHide]").each(function() {
if (!isNaN($(this).attr("AutoHide"))) {
eval("setTimeout(function() {jQuery('#" + this.id + "').hide();}, " + parseInt($(this).attr('AutoHide')) * 800 + ");");
}
});
});
})(jQuery);
HTML(或者至少,有问题的区域看起来像这样)
<div id="notify" class="infomsg">
<p><b>TIP:</b> Some message that should be prompted.
<input class="close msgbutton" type="button" onclick="deleteline(this)" value="[X]" />
</div>
<div id="notify" AutoHide="5" class="successmsg">
<p><b>SUCCESS: </b> User form processing was successful!</p>
<input class="close msgbutton" type="button" onclick="deleteline(this)" value="[X]" />
</div>
现在我不明白为什么 jQuery 函数没有删除带有 AutoHide 属性的 div,而是删除了没有的那个(它的 id 为“notify”)。
我认为罪魁祸首在于这部分代码:
jQuery('#" + this.id + "').hide();