<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script type="text/javascript" src="./js/jquery.js"></script>
<script>
$(document).ready(function(){
$("#name").blur(function(){
var a=$("#name").val();
if(a==''){
$("#showMsg").append("<p>输入不能为空</p>")
}
else{
$("#showMsg").empty()
}
})
$("#name").focus(function(){
$("#showMsg").empty()
})
})
</script>
</head>
<body>
企业名称:<input type="text" id="name"><br>
<div id="showMsg" class="show"></div>
企业法人:<input type="text" id="faren">
</body>
<style>
.show{
color: red;
font-size: large
}
</style>
</html>
- 当使用javascript时 可以使用innerHTML=" 要提示的话" 效果在现阶段和append相同
虽然jQuery在选择DOM节点时非常便利 但是在向节点中添加数据时感觉并不如js方便
jQuery的empty()方法存在弊端,在使用jQuery对节点进行文本的增加或删除时需要谨慎