表单新增元素与属性

来源:互联网 发布:finalcut mac 编辑:程序博客网 时间:2024/05/21 17:34
<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title></head><body><form>    <input type="text" formenctype="text/plain">    <!--表单中的数据空格被转换为加号但不对表单中的特殊字符进行编码-->    <input type="text" formenctype="multipart/form-data">    <!--不对字符进行编码在使用文件包含上传空间的表单时要使用该值-->    <input type="text" formenctype="application/x-www-form-urlencoded">    <!--在发送前编码所有字符(默认)(空格被编码为’+’,特殊字符被编码为ASCII十六进制字符)--></form></body></html>







<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title></title></head><body><script>    function validate(){    var txtName=document.getElementById("txt_name");    var button=document.getElementById("btnValidate");    var form=document.getElementById("testform");      if(txtName.value.trim()==""){          var label=document.createElement("label");          label.setAttribute("for","txt_name");          form.insertBefore(label,button);          txtName.labels[1].innerHTML="请输入姓名";          txtName.labels[1].setAttribute("style","font-size:9px;color:red");      }    }</script><form id="testform">    <label id="label" for="txt_name">姓名:</label>    <input id="txt_name">    <input type="button" id="btnValidate" value="验证" onclick="validate()"></form></body></html>




0 0
原创粉丝点击