相关疑难解决方法(0)

document.write清除页面

为什么在下面的代码中,document.write在函数调用时,validator()表单元素(复选框和按钮)将从屏幕中删除?

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function validator() {
                if (document.myForm.thebox.checked)
                    document.write("checkBox is checked");
                else 
                    document.write("checkBox is NOT checked");
            }
        </script>
    </head>
    <body>
        <form name="myForm">
            <input type="checkbox" name ="thebox"/>
            <input type="button" onClick="validator()" name="validation" value="Press me for validation"/>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript javascript-events

17
推荐指数
3
解决办法
4万
查看次数

标签 统计

html ×1

javascript ×1

javascript-events ×1