好友查询(例题)

<body>
<!--用户名查找-->
<form action="0621zuoye-2.php" method="post">
<div>用户名:
  <input type="text" id="name" name="name" />
  <input id="cz" type="submit" value="查找" />
</div>
</form>

<div>
<?php
  //调用数据库类文件
  include ("REN.class.php");
  //定义对象
  $a=new REN();
  //设置用户名的默认值为空
  $name="";
  //判断提交文本中是否有内容
  if(!empty($_POST) && $_POST!="")
  {
    //如果有就将该内容赋给name变量中
    $name=$_POST["name"];
  }
  //从数据库中进行查询的SQL语句
  $sql="select * from people where name='{$name}'";
  //执行该SQL语句
  $attr=$a->Query($sql);
  //将所需内容遍历出来
  foreach($attr as $v)
  {
    echo "<div class='f' bs='{$name}'>$v[2]</div>" ;
  }
?>

</div>
</body>

<script type="text/javascript">
$(document).ready(function(e) {
    //鼠标点击事件
    $(".f").click(function(){
    //对对象状态进行清空处理
    $(".f").css("background-color","#00F");
    $(".f").attr("xz","0");

    //改变选中项的背景颜色
    $(this).css("background-color","#F00");
    //建立一个新属性用来区分命令的执行
    $(this).attr("xz","1");
    //显示该对象相关的用户名
    alert($(this).attr("bs"));
  })

  //鼠标移入事件
  $(".f").mouseenter(function(){

  //改变选中内容的css样式的背景颜色
  $(this).css("background-color","yellow");
  })

  //鼠标移出事件
  $(".f").mouseleave(function(e) {
    //判断该项是否被选中,若没有被选中则进行背景色改变
    if($(this).attr("xz")!="1")
    {

      //改变选中内容的css样式的背景颜色
      $(this).css("background-color","#00F");
    }
  })
});
</script>

原文地址:https://www.cnblogs.com/m-m-g-y0416/p/5612108.html