使用添加用户按钮添加HTML字段

时间:2015-02-06 05:38:17

标签: javascript html

我想通过“ ADD USER 按钮在我的HTML代码中添加字段,以便在前三个字段中完成所有验证电子邮件 名称& 电话号码在新生成的3个字段中应该相同。我使用了Jquery validate插件。 我的HTML代码如下

<!DOCTYPE html>
<!--<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>-->

<html>
<head>
<meta charset="utf-8">
<title>Manageuser_addUser</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!--<script src="plugin/validation/dist/additional-methods.min.js"></script>-->
<script src="plugin/validation/dist/jquery.validate.min.js"></script>
<script src="plugin/utilities/validationutils.js"></script>


</head>
<body>

 <div>

  <h1>Manage Users!</h1>
  <form id="formRegistration" method="post" action="">

             <div>
            <label for="email">Email Id*</label>
            <input id="email" type="email" name="email" value="" placeholder="Enter your Email Id" />
            </div>

            <div>
            <label for="name">Name*</label>
            <input id="name" type="text" name="name" value="" placeholder="Enter your Name"  />
            </div>

我正在尝试使用js和J查询的这一部分,但它不能正常工作

   <script type="text/javascript">
    var i = 3;

   function addField(tableid)
  {
     var row = document.createElement("tr");
     var col1 = document.createElement("td");
      var col2 = document.createElement("td");
       var input = document.createElement("input");

      input.setAttribute("type","text");
         input.setAttribute("name","field" + i );

       col1.appendChild(document.createTextNode("Field" + i));
      col2.appendChild(input);

               row.appendChild(col1);
      row.appendChild(col2);

        var table = document.getElementById(tableid);

     table.appendChild(row);
      i++;
 }

             <div>
            <label for="phone">Phone</label>
            <input id="phone" type="text" name="phone" value="" placeholder="+xx-xxxxxxxxxx" />
            </div>



            <div>
            <input type="submit" name="add" value="Add User" id="publiclogin">
            </div>

            <div>
            <input type="submit" name="add" value="Add more Fields" id="">
            </div>


            </form>
           </div>
      </body>

1 个答案:

答案 0 :(得分:2)

你的javascript代码似乎不完整,应该有:

$("#formRegistration").validate();
脚本标签内的