首页>>Jquery文字>>jQuery实现开关效果,点击更改是否(2016-05-05)

jQuery实现开关效果,点击更改是否

jQuery实现开关效果,点击更改是否
赞赏支持
立刻微信赞赏支持 关闭

 

XML/HTML Code
  1. <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table_parameters">  
  2.                     <tbody>  
  3.                         <tr class="tr_head">  
  4.                             <td>用户名</td>  
  5.                             <td>是否审核</td>  
  6.                         </tr>  
  7.                         <?php  
  8.                         $sql = "SELECT * FROM users limit 0,10";  
  9.                         $query = mysql_query($sql);  
  10.                         while ($row = mysql_fetch_array($query)) {  
  11.                             ?>  
  12.   
  13.                             <tr>  
  14.                                 <td align="center"><?php echo $row['username']; ?></td>  
  15.                                 <td align="center"><a onclick="yes($(this), '<?php echo $row['user_id']; ?>')"><?php  
  16.                                         if ($row['status'] == 1) {  
  17.                                             echo "是";  
  18.                                         } else {  
  19.                                             echo "<span style='color:red'></span>";  
  20.                                         }  
  21.                                         ?></a></td>  
  22.                             </tr>     
  23. <?php } ?>  
  24.                     </tbody>  
  25.                 </table>  

 

JavaScript Code
  1. <script type="text/javascript">  
  2.                                 function yes(obj, id) {  
  3.                                     $.post("ajax.php", {  
  4.                                         id: id  
  5.                                     }, function(data) {  
  6.                                         if (data == "1") {  
  7.                                             obj.parent("td").html("<a onclick=yes($(this)," + id + ")>是</a>");  
  8.                                         } else {  
  9.                                             obj.parent("td").html("<a onclick=yes($(this)," + id + ")><span style='color:red'>否</span></a>");  
  10.                                         }  
  11.                                     })  
  12.                                 }  
  13.         </script>  

 


原文地址:http://www.freejs.net/article_jquerywenzi_555.html