0

以下は、onblur を使用して「動的」ID を示すアラートを作成する方法です。入力フィールドを含むwhileループがあるため、IDはデータベース内の一意のIDから取得されます。

どうすれば値も取得できますか?通常はいつものように変数を設定するだけですが、ループしているので方法がわかりません。

<script type="text/javascript">
    function doUpdateEntries(clicked_id) {
        alert(clicked_id);
        // how do I get the value AND id?
    }
</script>

while ($row = mysql_fetch_assoc($result)) {
    <input onblur="doUpdateEntries(this.id);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
}
4

2 に答える 2

2

doUpdateEntries値を別のパラメーターとして関数に渡すだけです。

<script type="text/javascript">
    function doUpdateEntries(id, value) {
        alert(id);
        alert(value);
    }
</script>

while ($row = mysql_fetch_assoc($result)) {
    <input onblur="doUpdateEntries(this.id, this.value);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">
}
于 2013-02-26T02:59:53.097 に答える
1

Ankit が言及しているように… を渡すだけですthis

<input onblur="doUpdateEntries(this);" id=".$row['entry_id']." name=".$row['entry_id']." type="text" value=".$row['reviews'].">

以下は、を使用して「動的」IDを示すアラートを作成した方法onblurです。入力フィールドを含むwhileループがあるためid、データベース内の一意の ID から取得されます。

どうすれば値も取得できますか?通常はいつものように変数を設定するだけですが、ループしているので方法がわかりません。

function doUpdateEntries(_this) {
    var _id = _this.id;
    var _name = _this.value;
}
于 2013-02-26T03:00:04.757 に答える