1

jquery でフォームから選択した値を使用する際に問題があります。それは密接に関連しています:

上記の(および他の)例を使用して、この作業を何時間も試みました。

口座番号のドロップダウン リストがあります。

    <form id="accounts">
        <select>
            <option value="">Select one</option>
            <c:forEach var="custAccount" items="${customerAccounts}">
                <option value=${customerAccount}>${customerAccount.accountId}</option>
            </c:forEach>
        </select>
    </form>

選択したアカウントを href で使用したい:

            <a href="Controller?&accountid='+selectedAccount+'&username=${username}&userid=${userid}&command=customerNewTransaction">Start new transfer</a>

そして、ここに私のスクリプトがあります:

    <script type="text/javascript">
      $(document).ready(function() {
        var selectedAccount;
        $("#accounts").change(function() {
           selectedAccount = $(this).text();
        });
      });
    </script>

これは機能せず、選択したテキストは毎回空です。また、同じ(不足している)結果で .val() も呼び出してみました。

私は何が欠けていますか?

4

3 に答える 3

0
<form id="accounts">
    <select id="account-select">
        <option value="">Select one</option>
        <c:forEach var="custAccount" items="${customerAccounts}">
            <option value=${customerAccount}>${customerAccount.accountId}</option>
        </c:forEach>
    </select>
    <div id="transfer-container">

    </div>
</form>

<script type="text/javascript">
  $(document).ready(function() {
      $("#account-select").change(function() {
          $('#transfer-container').html( '<a href="Controller?&accountid='+ $(this).val() +'">Start new transfer</a>' );
    });
  });
</script>
于 2013-11-12T19:34:28.983 に答える