我有一個行數組,每行都有一個單選按鈕(name ='status')。我已將單選按鈕放入索引中,以便每個單選按鈕都能反映其正確的值。但是,JavaScript不再能夠改變這個值 - 我對我需要對javascript做出的相應改變感到困惑。將單選按鈕放入索引後Javascript不工作
<form action="<?php echo $this->form_action; ?>" method="post">
<p class="hide"><input name="status" type="text" value="" /></p>
<table id="manage-items" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th><?php echo $this->translate('Item');?></th>
<th><th><?php echo $this->translate('Status');?></th></th>
</tr>
</thead>
<tbody>
<?php $ind = 0; ?>
<?php foreach ($this->items as $item) {
$item_link = 'type=product';
?>
<tr id="item_<?php echo $ind; ?>">
<td data-label="Title"><span class="orangelink"><?php echo $item->title; ?></span></td>
<td align="left" style="padding-left:22px" class="color-status-<?php echo $item['active']; ?>">
<?php if (in_array($item['active'], array(0, 1))) { ?>
<input type="radio" name="item[<?php echo $ind; ?>][status]" value="1" <?php if ($item['active'] == 1) echo 'checked'; ?>>Active
<br>
<input type="radio" name="item[<?php echo $ind; ?>][status]" value="0" <?php if ($item['active'] == 0) echo 'checked'; ?>>Inactive
<?php } else { ?>
<?php echo $item['active']; ?>
<?php } ?>
</td>
</tr>
<?php $ind++; ?>
<?php } ?>
</tbody>
</table>
</form>
<script type="text/javascript">
//console.log(jQuery)
head.ready('jquery', function() {
$(document).ready(function() {
$('input[name="radio"]').click(function() {
var status = this.value;
var id = $(this).parents('tr').attr('id');
console.log('here now')
$.ajax({
type: 'post',
url: "?module=items&controller=block&action=modDaStatusBro",
data: 'id=' + id + '&status=' + status,
beforeSend: function() {
$('#' + id).animate({
'backgroundColor': '#FFBFBF'
}, 400);
},
success: function (result) {
if (result == 'ok') {
$.get(window.location.href, function (data) {
$('#' + id).html($(data).find('#' + id).html());
setTimeout(function() {
$("#" + id + "").animate({'backgroundColor': 'transparent'}, 400).find('.tooltip').simpletooltip();
deletePage();
}, 500);
});
} else {
alert(result);
$("#" + id + "").animate({'backgroundColor': 'transparent'}, 400);
}
}
});
});
});
});
</script>
下載請你的代碼的相關部分粘貼到[的jsfiddle ](https://jsfiddle.net/),所以我們可以更好地調試它。 – Carpetfizz
@Carpetfizz剛剛粘貼了我在上面的內容:https://jsfiddle.net/7quo5akr/。不知道如何鏈接jsfiddle中的數據庫來說明多行。 – ian
在上面的小提琴文本輸入中單擊觸發ajax。但我很確定它應該通過點擊收音機來觸發。嘗試使用'$('input [type =「radio」]')。點擊(function(){'而不是'$('input [name =「status」]')點擊(function(){' –