1

フォーム フィールドを動的に作成しています。


私が使用する場合

<script>
$().ready(function() {

    $("input[name=salesPrice1]").blur(function() {

        var nameID = $("input[name=salesPrice1]").val();

        alert(nameID);

        //var newName = $("input#newName").val();

        $.ajax({
            type: "POST",
            url: "cashPrice.cfm",
            data: "salePrice=" + $("input[name=salesPrice1]").val(),
            cache: false,
            success: function(data) {
                $("#cashPrice1").html(data);
            }
        });
    });
});
</script>

部分的に動作します。ここで、formField の ID/名前を動的に取得する必要があります。どうすればいいですか?

4

3 に答える 3

1

あなたの質問はせいぜい漠然としています。しかし、これはあなたが望むものの線に沿っていますか?:

$("input").blur(function ()
{
    var that = $(this);

    var id = that.attr("id");
    var name = that.attr("name");
});



アップデート:

値の要素を一致させることができます:

$("input[id^='hello']")

一致します:

<input type="text" id="helloworld" />
<input type="text" id="helloearth" />

だがしかし:

<input type="text" id="hiworld" />

セレクターのドキュメントを参照してください。

注意:これらのセレクターは遅いので、最後の手段としてのみ使用します。パフォーマンスを高速化するために、DOM ノードのサブセットに対してクエリを実行できます。

$("complex selector goes here", $("container node in which to query"))
于 2009-06-19T19:39:04.780 に答える
0

これも機能します:

<html>
<script type="text/javascript">
    $().ready(function() {
        alert('loaded');
        $('.salesPriceInput').blur(function ()
        {    
            alert($(this).attr("id"));
            var myID = $(this).attr("id").substr(10,1); 
            alert(myID);
            $.ajax({
                type: "get",
                url: "cashPrice.cfm",
                data: "salePrice=" + $('#salesPrice'+myID).val(),
                cache: false,
                success: function(data){
                   $('#cashPrice'+myID).html(data);
                }
            })
         }); 
    });
</script>


<form>
    <cfoutput>
        <cfloop from="1" to="3" index="i">
            <input type="text" name="salesPrice#i#" id="salesPrice#i#" class="salesPriceInput" value="" />
            <div id="cashPrice#i#"></div>
            <hr />
        </cfloop>
    </cfoutput>
</form>
于 2009-06-19T20:18:05.903 に答える