0

料金計算機を作成したいのですが、そのためにフォームにアクセスする必要があるため、jQuery でそれを実行できるかどうか疑問に思いました。だから私のコードはそれです:

<form id="fee">
    <input type="text" title="fee" placeholder="Place the amount that you would like to send"/> $
    <input type="submit" onclick="getFee()"/>
</form>
<br/>
<p id="Here will be the fee"></p>

そしてJS:

function getFee(){
    $("fee > input:fee").
}

これが私の問題です。ユーザーが入力に入力した金額を取得し、この金額に 10% を追加して、下の段落に出力する方法を知りたいです。

4

4 に答える 4

0

出力 ID とセレクターを変更しました。 jsfiddle の例

属性セレクター

$(document).ready(function () {
    $("#fee")[0].onsubmit= getFee;

});
function getFee(){
        var feeInput = $('#fee > input[title="fee"]').val();
        feeInput = parseInt(feeInput);
        $('#Here_will_be_the_fee').text(feeInput*1.1);
        return false;
}

getFeeフォームが送信されないように false を返し、onsubmit イベントのみをトリガーします。

于 2013-04-11T20:33:10.730 に答える
0

これを試して

function getFee(){
    var inputVal = $("#fee > input[title='fee']").val();
    var inputFinal = parseInt(inputVal) + (parseInt(inputVal) * .10);

    //Change the ID of the p your appending to
    //ID is now = "calc"
    $("#calc").text(inputFinal);
}

デモはこちら: http://jsfiddle.net/Ln3RN/

于 2013-04-11T20:12:36.337 に答える
0

ID には # 記号を使用します。また、入力に id を追加します。id="feeInput"

また、タイトルは有効な入力タグではありません。

function getFee(){
        $("#fee > input#feeInput").
    }
于 2013-04-11T20:09:20.903 に答える