本文摘自PHP中文网,作者逆旅行人,侵删。

判断表单中的文本框的内容是否为空的方法有很多:1.通过php
语句判断 2.通过js
语句判断 3.通过html
原生语句进行判断。
1.通过PHP
语句判断 :
html中内容:
1 2 3 | < form action = "submit.php" method = "post" >
< textarea name = "text" ></ textarea >
</ form >
|
php中内容:
1 2 3 4 5 6 7 | <?php
if (isset( $_POST [ 'text' ]) && strlen (trim( $_POST [ 'text' ]))>0)
echo '不空' ;
else
echo '空 ' ;
?>
|
2.通过JS
语句判断
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <html>
<head>
<title>JS判断input是否为空</title>
<script> function op(){
if (document.getElementById( "ip" ).value== "" ){
alert( "input为空" );
} else {
alert(document.getElementById( "ip" ).value);
}
}
</script>
</head>
<body>
<input id= "ip" onblur= "op()" value= "JS" />
</body>
</html>
|
3.通过required
属性判断
阅读剩余部分
相关阅读 >>
Html5中文乱码怎么办
Html元素有哪些自带样式,如何去除
Html mark标签怎么用
Html怎么设置不换行
Html文字居中怎么设置
sHtml与Html的区别是什么
怎么用Html设置一个定时器
怎么在Html中插入视频和音频
向Html中插入视频并兼容所有浏览器的方法
Html中aside是什么意思
更多相关阅读请进入《Html》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 如何判断html中文本框内容是否为空