我有這個jquery, 然後我用foreach顯示我的數據庫中的所有記錄。php jquery獲取每個td的值,它在第一個td上獲得
現在我試圖做的是將值傳遞給jquery,但該值只讀了第一個td。
我的jQuery
jQuery('#nannyedit').click(function(){
jQuery('<img src="<?php echo plugins_url('images/jon-loader.gif', __FILE__); ?>" id="loading" />').appendTo("#container");
var unanny = jQuery(this).parent().siblings("input[name=nanny]:first").val();
var access = jQuery('input[name=access]').val();
alert(unanny);
jQuery.ajax({
type: "GET",
url: "<?php echo plugins_url('edit.php', __FILE__); ?>",
data: { user_login: unanny, access: access },
dataType: 'html',
target: '#tab-1',
success: function(data){
jQuery("#container").find('img#loading').remove();
jQuery("#container").html(data);
}
})
});
我的HTML
<table cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Status</th>
<th>Photo</th>
<th>Resume</th>
<th>Date</th>
<th>Option</th>
</tr>
</thead>
<tbody>
<?php
global $wpdb;
$mynanny = $wpdb->get_results("SELECT * FROM jon_nanny");
$color1 = "#FDF7E1";
$color2 = "#FFFFFF";
$row_count = 0;
foreach ($mynanny as $nanny) {
$mynannyphoto = $wpdb->get_row("SELECT * FROM jon_nanny_photo WHERE user_login = '".$nanny->user_login."' ");
$mynannyresume = $wpdb->get_row("SELECT * FROM jon_nanny_resume WHERE user_login = '".$nanny->user_login."' ");
$row_color = ($row_count % 2) ? $color1 : $color2;
$uploads = wp_upload_dir();
$upload_dir = ($uploads['url']);
?>
<tr>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->user_login; ?></td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->email; ?></td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->fname; ?></td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->mname; ?></td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->lname; ?></td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->user_status; ?></td>
<td style="background-color:<? echo $row_color; ?>">
<img src="<?php echo $upload_dir.'/'.$mynannyphoto->imgname; ?>" width="150" />
</td>
<td style="background-color:<? echo $row_color; ?>">
<a href="<?php echo $upload_dir.'/'.$mynannyresume->resume; ?>" />
<img src="<?php echo plugins_url('images/resume.png', __FILE__); ?>" />
</a>
</td>
<td style="background-color:<? echo $row_color; ?>"><?php echo $nanny->date; ?></td>
<td style="background-color:<? echo $row_color; ?>" id="getnan">
<?php
$url = admin_url();
?>
<input type="hidden" name="nanny" value="<?php echo $nanny->user_login;?>" />
<input type="hidden" name="access" value="nanny" />
<a href="#" id="nannyedit">
<img src="<?php echo plugins_url('images/edit-file-icon.png', __FILE__); ?>" />
</a>
<a href="">
<img src="<?php echo plugins_url('images/delete-file-icon.png', __FILE__); ?>" />
</a>
<a href="" title="View">
<img src="<?php echo plugins_url('images/Document-icon.png', __FILE__); ?>" />
</a>
</td>
</tr>
<?php
$row_count++;
}
?>
</tbody>
</table>
是我的jQuery的錯嗎? 請告訴我,謝謝。
使用類選擇,而不是id選擇使用'jQuery的。單擊(function(){'而不是'jQuery('#nannyedit')。click(function(){'並且更改html'' –
@Suchel Meman the警報值e是undefined,它的意思是它仍然沒有得到td的值.. – Butternut
@Suchel Meman感謝你的工作,現在我只需要移除.parent'jQuery(this).siblings(「input [name = nanny]」).val ();' – Butternut