2014-04-07 63 views
0

选择一个元素我有使用过Spring的代码是这样一种形式:形式,通过jQuery的

<form:form class="form-horizontal col-md-12" method="POST" action="../admin/new_laborItem.do" id="laborForm" modelAttribute="laborBean"> 
    <h5 class="text-info"><strong>Job Definition</strong></h5> 
    <div class="form-group"> 
     <label for="laborItem" class="col-sm-3 control-label">Item:</label> 
     <div class="col-sm-9"> 
      <form:input id="laborItem" path="item" type="text" required="required" class="form-control" placeholder="Labor Code"></form:input> 
     </div> 
    </div> 
</form:form> 

我想要得到的文本字段的文本,但我不知道为什么它不适用于此代码:

console.log($('#laborItem').text()); 
console.log($('#laborItem').html()); 

结果为空字符串。

enter image description here

我触发控制台的文本字段中键入测试按下一个按钮

回答

0

后,只需使用:

$('#laborItem').val() 

您将需要使用val() ATTR的jQuery到获取输入元素的值

+0

感谢您向我介绍'.val()'标签 – newbie