2010-02-17 49 views
0

我這樣像這樣通過一個循環,在一個頁面中列出的幾個表格中選擇輸入字段:(提取物)如何所列形式使用jQuery

if(mysql_num_rows($r)>0): 
while($row = mysql_fetch_assoc($r)): ?> 
     <form id="myForm" action="save_fb.php" method="post"> 

     Title: <input type="text" name="fb_title" value="<?php echo $row['fb_title']; ?>" /><br> 

    <a href="javascript:;" class="save_fb" id="<?php echo $row['fb_id']; ?>"></a> 


     </form> 
在我的Ajax請求

我做這樣的事情:

$.ajax({ 
    type: "POST", 
    data: $("input:text[name=fb_titel]").val()+$(this).attr("id"), 
    url: "save_fb.php", 
    success: function(msg) 
    { 
    $("span#votes_count"+the_id).fadeOut(); 
    $("span#votes_count"+the_id).html(msg); 
    $("span#votes_count"+the_id).fadeIn(); 
    } 
    }); 
}); 

現在我得到作爲一個結果總是第一排,而不是然而點擊的地方鏈接$(本)工作正常,但我不知道如何結合的行...任何人都知道,數據線應該如何看起來像?

感謝您的任何提示=)

回答

0

試試這個:

$.ajax({ 
    type: "POST", 
    data: $(this).prev("input[name=fb_title]").val()+$(this).attr("id"), 
    url: "save_fb.php", 
    success: function(msg) 
    { 
    $("span#votes_count"+the_id).fadeOut().html(msg).fadeIn(); 
    } 
    }); 
}); 
0

更改腳本像這樣的第三行....

data: $(this).parent().find("input:text[name=fb_title]").val()+$(this).attr("id"), 

您當前的腳本發現第一任何<input name="fb_title">的實例。如果您使用此功能,它只會以與您點擊的鏈接相同的形式找到<input name="fb_title">

+0

注意,我糾正你的 'fb_titel' 到 'fb_title' 太多的拼寫錯誤。 – jessegavin 2010-02-17 14:28:03

+0

謝謝,如果我嘗試這種方式 - 它返回'對象'-hmm? – 2010-02-17 17:53:50

0

的PHP/HTML:

mysql_num_rows($r)>0): 
while($row = mysql_fetch_assoc($r)): ?> 
     <form id="myForm-<?php echo $row['fb_id']; ?>" action="save_fb.php" method="post"> 

     Title: <input type="text" name="fb_title" value="<?php echo $row['fb_title']; ?>" /><br> 

    <a href="javascript:;" class="save_fb" id="<?php echo $row['fb_id']; ?>"></a> 


     </form> 

jQuery的:

var id = $(this).attr("id"); 
    $.ajax({ 
    type: "POST", 
    data: $("input:text[name=fb_titel]", "#myForm-" + id).val() + id, 
    url: "save_fb.php", 
    success: function(msg) 
    { 
    $("span#votes_count"+the_id).fadeOut(); 
    $("span#votes_count"+the_id).html(msg); 
    $("span#votes_count"+the_id).fadeIn(); 
    } 
    }); 
}); 
+0

這裏我得到結果'未定義'? – 2010-02-17 17:54:57