Javascript 无法使用jQuery获取textfield值

Javascript 无法使用jQuery获取textfield值,javascript,jquery,ajax,struts2,Javascript,Jquery,Ajax,Struts2,我有一个invoice.jsp页面,其中我必须使用jQuery计算文本框中的一些值 在我的发票中有一个数量文本框。如果用户输入数量,则应动态计算计算出的价格,即(总价=单价*数量),并显示在另一个名为“价格”的文本框中 现在我的电流输出如下: 我尝试了下面的代码来解决这个问题,但是我的jQuery代码无法获取unitpricetextfield数据。我不知道为什么。请检查下面的代码,并为我提供解决方案 invoice.jsp -------------------- -------------

我有一个
invoice.jsp
页面,其中我必须使用jQuery计算文本框中的一些值

在我的发票中有一个数量文本框。如果用户输入数量,则应动态计算计算出的价格,即
(总价=单价*数量)
,并显示在另一个名为“价格”的文本框中

现在我的电流输出如下:

我尝试了下面的代码来解决这个问题,但是我的jQuery代码无法获取
unitprice
textfield数据。我不知道为什么。请检查下面的代码,并为我提供解决方案

invoice.jsp

--------------------
--------------------
<script type="text/javascript">
  $(document).ready(function(){
    $(function() {
      $('input[name^="quantity"]').change(function() {
        var unitprice = $(this).siblings('input[name^="unitprice"]').val();
        alert("Unit price check="+unitprice);
        //problem in this line. Unable to get the unit price
        $(this).siblings('input[name^="price"]').val($(this).val() * unitprice);
      });
    });
  });
</script>
..............................
..............................
<!--
  Here I am iterating through a list from my dabase using strus2 framework tags.
  And defined my  input field values in struts2 tag eg. `<s:textfield.../>`
  is the same as `<input type="text".../>
-->
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <s:iterator  value="#session.BOK" status="userStatus">
    <tr style="height: 10px;">
      <td width="65%" align="left"><s:property value="bookTitile"/></td>
      <td width="10%" align="left">
        <s:textfield name="unitprice" value="%{price}" size="4"/>
      </td>
      <td width="10%" align="center">
        <s:textfield name="quantity" value="%{quantity}" size="2" />
      </td>
      <td width="15%" align="center">
        <s:textfield value="%{price}" name="" size="6"></s:textfield>
      </td>
    </tr>
  </s:iterator>
</table>
................................
................................
--------------------
--------------------
$(文档).ready(函数(){
$(函数(){
$('input[name^=“quantity”]”)。更改(函数(){
var unitprice=$(this).sibbines('input[name^=“unitprice”]').val();
警报(“单价检查=”+单价);
//此行出现问题。无法获取单价
$(this.slides('input[name^=“price”]).val($(this.val()*单价);
});
});
});
..............................
..............................
................................
................................
当我更改数量文本框中的任何值时,我的警报框显示“单价检查=未定义”。请检查我的代码并提出解决方案

更新:生成的html

 inside loop {
  <tr style="height: 10px;">
    <td width="65%" align="left">book title display</td>
    <td width="10%" align="left">
      <input type="text" name="unitprice" value="%{price}" size="4"/>
    </td>
    <td width="10%" align="center">
      <input type="text" name="quantity" value="%{quantity}" size="2" />
    </td>
    <td width="15%" align="center">
      <input type="text" value="%{price}" name="" size="6"></s:textfield>
    </td>
  </tr>
内部循环{
书名显示
我让它工作了:


@Ibu我更新了在更新时再次检查我的上述代码:你建议的生成的htmlas。如果我在代码中应用,那么它会影响我的所有项目。也就是说,如果我更改了一个项目的数量,那么它也会影响我发票中的所有项目。我只想反映那些项目的价格,其数量不会更改为全部。我们如何做是吗?Ashu请用jsbin链接检查新的ans。很抱歉jai。您的答案仍然没有给出准确的输出。有时它在变化,有时它不随确切的单价变化。它与其他项目冲突。
$(function() {
  $('input[name="quantity"]').change(function() {
      var unitprice = $(this).parents('tr').find('input[name="unitprice"]').val();
      $(this).parents('tr').find(' input[name="price"]').val($(this).val() * unitprice);

    });
});