0

アクティブ化ボタンがクリックされたときにコードを実行する 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>
4

2 に答える 2

0
<script type="text/javascript">

        $('document').ready(function(){
            switch=0;
            $('a.activation').click(function(){
               if(switch==0){
                   var de_id = $(this).attr('de_id');
                   var parent = $(this).parent();
                   $.post('insert.php', {de_id:de_id});
                   switch=1;
                   $(this).css("background","green").html('Activate');
                   }
              else{
                     var act_id = $(this).attr('act_id');
                     var parent = $(this).parent();
                     $.post('insert.php', {act_id:act_id});
                     switch=0;
                     $(this).css("background","red").html('Deactivate');
                  } 
            });

    });// ready end

</script>

html

<a class='activation' onClick=\"reply_click(this.{$news['ns_id']})\" href=\"javascript:return(0);\"act_id=\"{$news['ns_id']}\" de_id=\"{$news['ns_id']}\" style=\"display: inline-block;\" ><img src=\"images\icons\activate.png\" height=\"16px\" width=\"16px\"  /></a>
于 2013-10-22T10:31:26.910 に答える
0

JS

    $('document').ready(function(){
        $('a.activation').click(function(e){
            var de_id = $(this).attr('de_id');
            var parent = $(this).parent();
            $.post('insert.php', {de_id:de_id});
            $("#"+e.target.id).toggle();
        });

        $('a.activation').click(function(e){
            $('a.activation').toggle();
            var act_id = $(this).attr('act_id');
            var parent = $(this).parent();
            $.post('insert.php', {act_id:act_id});
            $("#"+e.target.id).toggle();
        });
    });

</script>

html

echo "<a id='someid' 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 id='someotherid' 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>";
于 2013-10-22T10:27:11.853 に答える