我还在学习 jQuery,但遇到了问题。我有一张有 50 多行的表。每个都标有一个 id。
<tr id="51">
这个 id 是数据库 id,我需要将它传递给 jQuery 并与 AJAX 请求一起提交。
$($location).click(function () {
var $currentSelection = $(this);
// if there is already an input-field in this TD, return...
if($currentSelection.find('select').length > 0)
return;
$currentSelection.html('');
$('<select id="selectLocation" onChange="locationSubmit()"/>')
.attr('name', 'location')
.append('<option>Location 1</option>', '<option>Location 2</option>', '<option>Location 3</option>')
.appendTo(this);
});
locationSubmit()
function locationSubmit(){
var $selectLocation = $('#selectLocation').val();
var $selectId = $(this).val('tr#id'); //stuck here
alert($selectId);
$.ajax({
url: '/ajax/training-update.php',
data: {
action: $selectLocation,
courseid: $selectId
},
type: 'POST',
success: function(output) {
alert(output);
}
});
}
中的警报locationSubmit()
正在返回 [object Object]。如何传递tr#id
to的值locationSubmit()
并通过 AJAX 发送?
编辑 - HTML
<tr id="51">
<td><a href="/link/goes/here.php?course_id=5&id=51">course name</a></td>
<td>
<span class="rowStartDate" id="rowStartDate151">09/10/12</span> -
<span class="rowEndDate" id="rowEndDate151">09/14/12</span>
</td>
<td class="location">Location 2</td>
<td class="status">open</td>
</tr>