js中提示input中为空的情况

图片说明
怎么用js做这种效果,求代码

 <style>
    input.error{border:solid 1px #f00}
    span.error{color:#f00;display:none}
</style>
<input type="text" onblur="this.className = this.value == '' ? 'error' : ''; this.nextSibling.style.display = this.value == '' ? 'inline' : 'none'" /><span class="error">不能为空!</span>

肯定要写一个判断啊。贴一下你的页面,你用的是easy ui还是单纯的js?

写一个校验程序,在加上js,css估计就可以,前台没做过

简单,就是失去焦点的时候,判断内容是否为空 input 表示当前框,span 后面存那一串文本的标签

$('input').blur(function(){
if(input.value=="")
$('span').show();
$('span').hidden;
})