0

invoice.jspjQueryまたはその他の方法を使用して、テキストボックス内の値を計算する必要があるページがあります。

jQueryについてはよくわかりません。この問題を解決するのを手伝ってください。

請求書に数量のテキストボックスがあります。ユーザーが数量を入力すると、計算された価格が動的に計算(total_subPrice= unit_price * quantity)され、「価格」という別のテキストボックスに表示されます。

ここでも、すべての価格の合計が合計としてボタンに表示されます。

注意: すべての行の値は、ユーザーによる項目の選択に基づいてデータベース テーブルから取得されます。

このコードのみを使用して、invoice.jspページに値を表示しました。

<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:property value="price"/></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>

そして、私のinvoice.jsp出力は次のようになります。 ここに画像の説明を入力

line Total選択した数量に基づいてを計算し、line total総計テキスト ボックスにすべての合計を表示する方法がわかりません(下の請求書の画像を参照)。

これも試し ましたが、まだ問題を解決できません。

私の完全な JSP コード:

<table width="100%" height="50%" border="0" cellpadding="0" cellspacing="0">
  <tr>
  <td height="74%">
    <s:form action="dfs" id="form3"  theme="simple">
      <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"  id="your_content">
        <tr>
          <td valign="top" height="10%">
            <div id="invNum">Invoice# 12688</div>
            <div id="ttielMain">Vision Books</div>
            <div id="Orgaddress">    Thamel Kathmandu Nepal</div>
            <div id="phoneNum">  Tel# 00977-1-12173803</div>
            <div id="websiteOrg"> www.thebestbookfinder.com</div>
          </td>
        </tr>
        <tr>
          <td valign="top" width="100%" align="left">
          ----------------------------------------------------------- -----------------------------------
          </td>
        </tr>
        <tr>
          <td height="6%" valign="top" width="100%">
            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr style="height: 10px;font-family: serif;font-weight: bold;font-size: 14px;">
                <td width="65%" align="left">Title</td>
                <td width="10%" align="left">Unit Price</td>
                <td width="10%" align="center">Qty</td>
                <td width="15%" align="left">Line Total</td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td height="1%" valign="top" width="100%">
            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr style="height: 10px;">
                <td width="65%" align="left">
                -------------------------------------------------------
                </td>
                <td width="10%" align="left">----------</td>
                <td width="10%" align="center">-----</td>
                <td width="15%" align="left">-------------</td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td height="65%" valign="top" width="100%">
            <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:property value="price"/></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>
          </td>
        </tr>
        <tr>
          <td height="1%" valign="top" width="100%">
            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr style="height: 10px;">
                <td width="100%" align="right" colspan="5">
                ------------------------------------
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td height="1%" valign="top" width="100%">
            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
              <tr style="height: 10px;">
                <td width="100%" align="right" colspan="5" style="font-weight: b">
                  <s:set var="total" value="%{0}" />
                  <s:iterator value="#session.BOK">
                    <s:set var="total" value="%{price + #attr.total}" />
                  </s:iterator>
                  <s:textfield name="subtotal" value="%{'' + #attr.total}" size="5"> </s:textfield>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </tr>
      <tr>
        <td height="1%" valign="top" width="100%">
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr style="height: 10px;">
            <td width="100%" align="right" colspan="5">Discount:<sj:textfield name="amt"  size="1"  placeholder=" %"/></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="1%" valign="top" width="100%">
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr style="height: 10px;">
            <td width="100%" align="right" colspan="5">
            --------------------------------------------------------------------------------------------------
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="1%" valign="top" width="100%">
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr style="height: 10px;">
            <td width="100%" align="right" colspan="5" style="font-weight: bolder;">
              <s:set var="total" value="%{0}" />
              <s:iterator value="#session.BOK">
                <s:set var="total" value="%{price + #attr.total}" />
              </s:iterator>
              Total: <s:property value="%{'' + #attr.total}" />
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="1%" valign="top" width="100%">
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr style="height: 10px;">
            <td width="100%" align="right" colspan="5">
            --------------------------------------------------------------------------------------------------
            </td>
          </tr>
        </table>
      </td>
    </tr>
4

2 に答える 2

0

@flow が言ったように、.change() を使用します。

$(function() {
    $('input[name^="quantity"]').change(function() {
        var unitprice = $(this).siblings('input[name^="unitprice"]').val();
        $(this).siblings('input[name^="price"]')
               .val($(this).val() * unitprice);
    });
});
于 2012-11-17T15:00:43.277 に答える
0

入力で使用.change()します。

jQuery ドキュメント - 変更

于 2012-11-17T13:52:18.957 に答える