アクティブ化ボタンがクリックされたときにコードを実行する JavaScript の関数があります。この関数をトグル (変更) しますが、このコードをより具体的にしたいです。ID をこの関数に送信し、そのオブジェクトのみをトグルします。
たとえば、私はこれを行います:しかし、関数でそのリンクのIDを取得できません
また、以下の私のコードを見ることができます:
これは私のJavaScript関数です:
<script type="text/javascript">
$('document').ready(function(){
$('a.activation').click(function(){
var de_id = $(this).attr('de_id');
var parent = $(this).parent();
$.post('insert.php', {de_id:de_id});
$('a.activation').toggle();
});
$('a.activation').click(function(){
$('a.activation').toggle();
var act_id = $(this).attr('act_id');
var parent = $(this).parent();
$.post('insert.php', {act_id:act_id});
$('a.activation').toggle();
});
});
</script>
これが本体です:
<td><?php if($news['ns_act']==1){
echo "<a class='activation' onClick=\"reply_click(this.{$news['ns_id']})\" href=\"javascript:return(0);\" de_id=\"{$news['ns_id']}\" style=\"display: inline-block;\" ><img src=\"images\icons\activate.png\" height=\"16px\" width=\"16px\" /></a>
<a class='activation' onClick=\"reply_click(this.{$news['ns_id']})\" href=\"javascript:return(1);\" act_id=\"{$news['ns_id']}\" style=\"display:none;\" ><img src=\"images\icons\deactivate.png\" height=\"16px\" width=\"16px\" /></a>";
}
else {
echo "<a class='activation' onClick=\"reply_click(this.{$news['ns_id']})\" href=\"javascript:return(1);\" act_id=\"{$news['ns_id']}\" style=\"display: inline-block;\" ><img src=\"images\icons\deactivate.png\" height=\"16px\" width=\"16px\" /></a>
<a class='activation' onClick=\"reply_click(this.{$news['ns_id']})\" href=\"javascript:return(0);\" de_id=\"{$news['ns_id']}\" style=\"display:none;\"><img src=\"images\icons\activate.png\" height=\"16px\" width=\"16px\" /></a>";
}
?></td>