JS初级实战练习题----附答案

https://blog.csdn.net/u012310056/article/details/78050985

使用for循环获取表单元素中文

<script type="text/javascript">
function deal(form){
    for(i=0; i < form.length; i++){
        if(form.elements[i].value == ''){
            alert(form.elements[i].title + "不能为空");
        }
    }
}
</script>

<form name="form1">
<tr>
    <td>销售编号:</td>
    <td><input type="text" name="num" title="销售编号"></td>
</tr>
<input type="button" onClick="deal(this.form);" id="change" value="提交">
<input type="reset"  value="重置"/>
</form>

或者 我想提交以后获取输入的元素

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
        <form name="form1">
                <tr>
                    <td>销售编号:</td>
                    <td><input type="text" name="num" title="销售编号" id="one"></td>
                </tr>
                <input type="button" onClick="deal();" id="change" value="提交">
                <input type="reset"  value="重置"/>
        </form>
    <script>
        
        function deal(){
            var one=document.getElementById("one").value;
            alert(one);
        }
    </script>     
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44769592/article/details/91473341