[英]Javascript newbie question
i am using a jquery plugin to upload files, the plugin checks the file dimension and return back the appropriate error message. 我正在使用jquery插件上传文件,该插件检查文件尺寸并返回适当的错误消息。 the error message i am displaying is with this code. 我显示的错误消息与此代码有关。
$('#divmsg6').append("<p class = 'red'>Incorrect file dimension, try again</p>");
now if the user keep on trying the error will keep on appending, that's what append is meant for. 现在,如果用户继续尝试该错误,将继续添加,这就是添加的含义。 instead of appending i want my error code to be replaced every time it finds one. 而不是附加,我希望每次发现错误代码时都将其替换。 what is the js code for that? 这是什么js代码?
您可以使用html()
方法:
$('#divmsg6').html("<p class = 'red'>Incorrect file dimension, try again</p>");
For me, it would be better to hide/show error than, removing/adding the same thing. 对我来说,隐藏/显示错误比删除/添加相同的东西要好。
html html
<div id="divmsg6"><p class = 'red'>Incorrect file dimension, try again</p></div>
css 的CSS
#divmsg6 p.red {
display: none;
}
when error occurs, jQuery it like this, 当发生错误时,jQuery这样,
$('#divmsg6 p.red').show(); // show error message.
then you might want to hide on some time. 那么您可能想隐藏一段时间。
$('#divmsg6 p.red').show(function(){
var $this = $(this);
setTimeout(function(){
$this.fadeOut(1500);
},1500);
});
or any other variation of hiding it will do, just show it again when error occur. 或将其隐藏的任何其他变体,只要在发生错误时再次显示即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.