html中文本框未输入,旁边立刻出现红色警示字,如何做到?

如图所示

方法一、可以加载js插件(网上有很多这类验证表单的插件)
方法二、自己手动写,比如:
<form method="post" action="" onsubmit="return check_form(this)">
<div class="item">
<input type="text" name="name" oninput="clear_error(this)"/>
</div>
<button type="submit">提交</button>
</form>
<script type="text/javascript" src="引用jquery.js"></script>

<script type="text/javascript">
function check_form(f){
if(f.name.value == ''){
$('input[name="name"]').after('<span style="color:red;">请填写姓名</span>');
return false;
}
return true;
}
function clear_error(o){
$(o).siblings('span').remove();
}
</script>
温馨提示:答案为网友推荐,仅供参考