好的我有2条错误消息正在返回,而这些消息反过来显示同一条消息的2条消息。我怎么才能只显示一条消息?
jQuery.noConflict();
jQuery(document).ready(function(){
if (jQuery("span.errorMessage").length > 0) {
var $this = jQuery("span.errorMessage");
var t = $this.text();
// Clear the text
$this.text('');
// Add new message
$this.text('No search criteria was specified.');
// Change the layout
jQuery('#errorMessage').appendTo(jQuery('#message_display'));
}
});
为错误添加HTML
<span id="errorMessage">
<ul>
<li><span class="errorMessage">No search criteria was specified.</span></li>
<li><span class="errorMessage">No search criteria was specified.</span></li>
</ul>
</span>
答案 0 :(得分:2)
您似乎将文本附加到#errormessage,但清除#this.text()。我猜你需要在添加新错误之前清除#errormessage。
试试这个......
<div id="errorMessage">
<ul>
<li><span class="errorMessage">1 No search criteria was specified.</span></li>
<li><span class="errorMessage">2 No search criteria was specified.</span></li>
<li><span class="errorMessage">3 No search criteria was specified.</span></li>
<li><span class="errorMessage">4 No search criteria was specified.</span></li>
</ul>
</div>
$(document).ready(function() {
SetupMessageManager();
$('.errorMessage').parent().hide();
$('.errorMessage:first').parent().show();
});