html5中,input标签里required属性设置为false,为什么表单为空时还是提醒不能为空?

html5中,input标签里required属性设置为false,为什么表单为空时还是提醒不能为空?,第1张

required属性值是布尔类型。只要你写了 required = “xx”不管这xx是什么都会有效。
“false”本质上是一个字符串,当然有效。
让requried不起作用的方式就是 删掉它~!!

简单改了下你的,效果实现了,规范的写法自己改改吧

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8"/>  
    <title>checkValidity 示例</title> 
    <style>
      inputdd::-webkit-input-placeholder{
          color: red;
          opacity:1;
      } 
       
    </style>
</head>  
<body> 
<form action="" method="get">
<table width="200%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td><input class='' id='id' name="uname" type="text" placeholder="ID" onblur="aa(this)"></td>
  </tr>
  <tr>
    <td><input name="pwd" type="password" placeholder="密码"></td>
  </tr>
  <tr>
    <td><input name="" type="submit"></td>
  </tr>
</table>
</form>
<script> 
  function aa(a){
      if(avalue==''){
        aplaceholder='ID不能为空';
       aclassName="dd";
      }
  }
</script>
</body>  
</html>

您好!很高兴为您解答:

这个么很简单的嘛,用js检测一下就知道了,如下:

姓名:<input type="text" value=""  id="user"/><br><p>用户名不能为空</p>
密码:<input type="text" value=""  id="paw"/><br><p>密码不能为空</p>
年龄:<input type="text" value=""  id="age"/><br><p>年龄不能为空</p>
<input type="button" value="提交" id="btn"/>
<script>
var btn=documentgetElementById('btn');
var user=documentgetElementById('user');
var paw=documentgetElementById('paw');
var age=documentgetElementById('age');
var p=documentgetElementsByTagName('p');
for(var i=0;i<plength;i++){
p[i]styledisplay='none';
}
btnonclick=function(){

if(uservalue==''){
p[0]styledisplay='block';
}else{
p[0]styledisplay='none';
}
if(pawvalue==''){
p[1]styledisplay='block';
}else{
p[1]styledisplay='none';
}
if(agevalue==''){
p[2]styledisplay='block';
}else{
p[2]styledisplay='none';
}
}
</script>
望采纳

<html>

<head>

<title>同一个页面中多表单提交</title>

<scripttype="text/javascript">

functionmyCheck1()

{

if(form1text1value=="")

{

alert("内容不能为空,请输入内容");

form1text1focus();

return;

}

form1submit();

}

functionmyCheck2()

{

if(form2text2value=="")

{

alert("内容不能为空,请输入内容");

form2text2focus();

return;

}

form2submit();

}

functionmyCheck3()

{

if(form3text3value=="")

{

alert("内容不能为空,请输入内容");

form3text3focus();

return;

}

form3submit();

}

</script>

</head>

<body>

<formname="form1"method="post"action="#">

表单一:<inputname="text1"type="text">

<inputname="submit1"type="submit"value="提交"οnclick="myCheck1();">

</form>

<formname="form2"method="post"action="#">

表单二:<inputname="text2"type="text">

<inputname="submit2"type="submit"value="提交"οnclick="myCheck2();">

</form>

<formname="form3"method="post"action="#">

表单三:<inputname="text3"type="text">

<inputname="submit3"type="submit"value="提交"οnclick="myCheck3();">

<%

requestsetCharacterEncoding("UTF-8");

Stringtext1=requestgetParameter("text1");

Stringtext2=requestgetParameter("text2");

Stringtext3=requestgetParameter("text3");

Stringmessage="";

if(text1!=null)

{

message="你提交了第1个表单,表单内容为:"+text1;

}

if(text2!=null)

{

message="你提交了第2个表单,表单内容为:"+text2;

}

if(text3!=null)

{

message="你提交了第3个表单,表单内容为:"+text3;

}

%>

<h2><%=message%></h2>

</form>

</body>

</html>

扩展资料

在HTML文档中,<form></form>标记对用来定义表单的开始和结束。在表单<form></form>之间嵌入各类表单控件标记(表单元素)——如文本输入框、列表框、单选按钮、提交按钮等——供用户输入信息数据。

表单控件标记和表单<form>标记一起工作,共同发挥作用<form>标记的重要属性。<input>能够演变为表单中许多不同的元素,取决于type属性。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13391847.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-27
下一篇 2023-07-27

发表评论

登录后才能评论

评论列表(0条)

保存