jQuery实现开关效果,点击更改是否
XML/HTML Code
- <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table_parameters">
- <tbody>
- <tr class="tr_head">
- <td>用户名</td>
- <td>是否审核</td>
- </tr>
- <?php
- $sql = "SELECT * FROM users limit 0,10";
- $query = mysql_query($sql);
- while ($row = mysql_fetch_array($query)) {
- ?>
- <tr>
- <td align="center"><?php echo $row['username']; ?></td>
- <td align="center"><a onclick="yes($(this), '<?php echo $row['user_id']; ?>')"><?php
- if ($row['status'] == 1) {
- echo "是";
- } else {
- echo "<span style='color:red'>否</span>";
- }
- ?></a></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
JavaScript Code
- <script type="text/javascript">
- function yes(obj, id) {
- $.post("ajax.php", {
- id: id
- }, function(data) {
- if (data == "1") {
- obj.parent("td").html("<a onclick=yes($(this)," + id + ")>是</a>");
- } else {
- obj.parent("td").html("<a onclick=yes($(this)," + id + ")><span style='color:red'>否</span></a>");
- }
- })
- }
- </script>
原文地址:http://www.freejs.net/article_jquerywenzi_555.html