首页前端开发JavaScript如何判断html中文本框内容是否为空

如何判断html中文本框内容是否为空

时间2024-01-29 13:07:03发布访客分类JavaScript浏览576
导读:收集整理的这篇文章主要介绍了如何判断html中文本框内容是否为空,觉得挺不错的,现在分享给大家,也给大家做个参考。 判断表单中的文本框的内容是否为空的方法有很多:1.通过php语句判断 2.通过js语句判断 3.通过htML原生语句...
收集整理的这篇文章主要介绍了如何判断html中文本框内容是否为空,觉得挺不错的,现在分享给大家,也给大家做个参考。

判断表单中的文本框的内容是否为空的方法有很多:1.通过php语句判断 2.通过js语句判断 3.通过htML原生语句进行判断。

1.通过PHP语句判断 :

html中内容:

form action="submIT.php" method="post">
    textarea name="text">
    /textarea>
    /form>
    

php中内容:

//submit.php?phpif(isset($_POST['text']) &
    &
     strlen(trim($_POST['text']))>
    0)echo '不空';
    elseecho '空 ';
    ?>
    

2.通过JS语句判断

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属性判断

html lang="en">
    head>
        meta charset="UTF-8">
        meta http-equiv="X-UA-Compatible" content="IE=Edge">
        meta name="viewport" content="width=device-width, initial-scale=1.0">
        title>
    表单/title>
    /head>
    body>
        form action="" style="display: grid;
    " method="POST">
             div>
            label for="username">
    账号:/label>
            input tyPE="text" id="username" required>
                                      !--required为必须填写数据-->
        /div>
    /body>
    /html>
    

推荐:《html知识》

以上就是如何判断html中文本框内容是否为空的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

html

若转载请注明出处: 如何判断html中文本框内容是否为空
本文地址: https://pptw.com/jishu/591119.html
html与xhtml的区别有哪些 深入解析html中列表的几种方式

游客 回复需填写必要信息