添加动态输入

时间:2015-07-16 08:27:58

标签: javascript jsf dynamic

您好我想动态添加tbody所以每次在plannedvisit中的类型号添加一个tbody但是我收到了一个错误。我正在使用jsf和javaScript这是我到目前为止所做的:

我通过输入numeber来调用javascript函数:

 <h:inputText type="number" id="plannedVisit" styleClass="form-control"
       onkeyup=" addInput('dynamicInput'); return false; " required="true" >
    </h:inputText>


<div class="form-group"><div class= "col-sm-6" >
    <div id="nextVisitTable" class="input-group table">
        <table id="nextVisitTable1" class="table" style="width:10%;margin-  top:-210px; margin-left:90px; overflow:auto;">
           <thead>
              <tr>
                 <th>Reason</th>
                 <th>Date</th>
                 <th>Time</th>                                          
               </tr>
          </thead>
      <tbody>
      <tr>
      <td><h:inputText type="number" class="reasonOfVisit" styleClass="form- control"
required="true">

        </h:inputText></td>
    <td><h:inputText type="date" class="reasonOfVisit" styleClass="form-control"required="true">

      </h:inputText></td>

   </tr>                                                
   </tbody>
   </table>   
   </div>                                       
</div>

这是脚本:

function addInput(divName){
           var counter = 1;
           console.log(counter);
           var limit = 3;
                 if(counter == limit){ 
                 alert("You have Reached the Limit");
                 }
                  else {
          var newdiv = document.createElement('tbody');
          newdiv.innerHTML = "<tr><td><h:inputText type="number" class="reasonOfVisit" styleClass="form-control" required="true">
                              </h:inputText></td>
                              <td><h:inputText type="date" class="reasonOfVisit" styleClass="form-control" required="true">
                              </h:inputText></td>
                              </tr>"; 
          counter++;   
     }
                }

,错误是: SyntaxError:missing;在声明之前 在这一行

newdiv.innerHTML = "<tr><td><h:inputText type="number....</tr>"

我不确定这是否正确无论如果您有任何想法请帮忙。 感谢

1 个答案:

答案 0 :(得分:-1)

试试这个

if row[1] =="Raj" and row[2] == "male"
print "Its a boy"

和你的HTML

var counter = 1,
    limit = 3;
function addInput(event)
{
    if(counter == limit){
        alert("You have Reached the Limit");
    }
    else {
        var newdiv = document.createElement('tbody');
        newdiv.innerHTML = '<tr><td><h:inputText type="number" class="reasonOfVisit" styleClass="form-control" required="true">
                      </h:inputText></td>
                      <td><h:inputText type="date" class="reasonOfVisit"   styleClass="form-control" required="true">
                      </h:inputText></td>
                      </tr>'; 
        counter++;
    }
}

window.onload = function() {
    var element = document.getElementById("plannedVisit");
    element.addEventListener("keyup", addInput, false);
};