繁体   English   中英

如何在有序列表中显示功能的输入

[英]How to display inputs of a function in an ordered list

我需要编写一个代码,创建一个具有三个兴趣的表单。 当用户提交它们时,它们需要出现在列表中。 到目前为止,我有此编码:

当我单击“提交”时,我不会被指引到任何地方。

<html>
   <head>
    <script>
function validateForm()
{var x=document.forms["myForm"]["interest1"].value;
var y=document.forms["myForm"]["interest2"].value;
var z=document.forms["myForm"]["interest3"].value;

}
</head>
    </script>

    <body>
      <form name="myForm" action="demo_form.asp" onsubmit=return validateForm()" method="post">
        Interest 1:<input type="text"  name="interest1">
        Interest 2:<input type="text" name="interest2">
        Interest 3:<input type="text" name="interest3">
        <input type="submit" value="Submit">
      </form>


    </body>
</html>

我需要使用一个for循环来获取提交的值。 我该怎么做呢?

由于您是在提交时返回函数,因此如果要提交,请尝试从函数返回true

<script>
function validateForm() {
    var x=document.forms["myForm"]["interest1"].value;
    var y=document.forms["myForm"]["interest2"].value;
    var z=document.forms["myForm"]["interest3"].value;

    // TODO: validate x, y and z

    return true;
}
</script>

您的结束标记的顺序也不正确,请确保</script>出现在</head>之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM