私はこの問題に直面しているこのプロジェクトに取り組んでいます。ロード後にクリックすると、コードが機能します。各ユーザーに id を使用しました。これはアクティブ/非アクティブ ユーザー用のコードです。ID を各テキストボックスとスパンに渡しました。機能していません。この問題を解決する方法についていくつかのアイデアを提供してください。PHP コード:
<!--top section start-->
<?php $this->load->view("header");?>
<div id="wrapper" style="height: auto;">
<div class="user_intro">
<table width="600" height="300">
<th style="text-align:left;">First Name</th>
<th style="text-align:left;">Email</th>
<th style="text-align:center;">Active Status </th>
<?php
foreach($result as $user)
{?>
<tr>
<td style="text-align:left;"><a href="<?php echo base_url()?>siteadmin/home/userdetail?userid=<?php echo $user->user_id; ?>"><?php echo $user->first_name;?></a></td>
<td style="text-align:left;"><a href="<?php echo base_url()?>siteadmin/home/userdetail?userid=<?php echo $user->user_id; ?>"><?php echo $user->email;?></a></td>
<?php if ($user->status == 1) { ?>
<td style="text-align:center;"><input type="button" id="<?php echo $user->user_id; ?>" value="" class="on" onclick="togglestyle(this,this.id)" /> </td>
<td><span id="reason_<?php echo $user->user_id; ?>"><input type="text" value="<?php echo $user->reason; ?>" /> </span></td>
<?php }
else {?>
<td style="text-align:center;"><input type="button" id="<?php echo $user->user_id; ?>" value="" class="off" onclick="togglestyle(this,this.id)" /> </td>
<td><span id="reason_<?php echo $user->user_id; ?>"><input type="text" value="<?php echo $user->reason; ?>" /> </span></td>
<?php } ?>
</tr>
<?php }
?>
</table>
</div>
</div>
<!--fotter section start-->
</div> <?php $this->load->view("footer"); ?>
ヘッダーファイルに追加したjavascriptコード.:
<script type="text/javascript">
function togglestyle(el, id) {
if (el.className == "on") {
$("#reason_" + id).show();
$.ajax({
type: "POST",
url: "statuson",
data: "userid=" + id,
success: function (html) {
if (html == 'true') {
el.className = "off";
}
},
});
} else {
$("#reason_" + id).hide();
$.ajax({
type: "POST",
url: "statusoff",
data: "userid=" + id,
success: function (html) {
if (html == 'true') {
el.className = "on";
}
},
});
}
}
</script>