日期:2014-05-16  浏览次数:20460 次

AJAX PHP 循环之后点击状态更换图片
  <?php
                 foreach ( $account as $key => $value)
         {
    ?> 
 <!-- 图片的状态 1 显示 2 隐藏 -->
          <?php if($value['starflag'] == 1){ ?>
        <a href="javascript:void(0);" onclick="xingxing('<?php echo $value['id']."','".$value['name']; ?>');">
          <img src="/themes/default/images/star02.gif" im="images/star02.gif" /> 
        </a>
        <?php 
          }
        else{
        ?>
        <a href="javascript:void(0);" onclick="xingxing('<?php echo $value['id']."','".$value['name']; ?>');">
          <img src="/themes/default/images/star01.gif"  im="images/star01.gif" /> 
        </a>
        <?php } ?>    
        </a>

<?php } ?>

function xingxing(id,name){
       $.ajax({
          type: "POST",
          url: "<?php echo base_url('test/fangfa'); ?>",
          processData: "false",
          data: "n=" + Math.random() + "&fn=" + escape(id) + "&starflag=" + escape(name) + "",
          success: function(msg){
            var msg = $.trim(msg);
            switch (msg){
              case "200":
                 location.replace(location.href);
              case "110":  //重新登录
                location.replace(location.href);
              case "120":  //修改密码
                location.replace(location.href);
                break;
              default:
                alert("失败");
                lo