jQuery和PHP打造功能开关效果
课程导航
    jQuery和PHP打造功能开关效果报名
    jQuery和PHP打造功能开关效果新闻
    jQuery和PHP打造功能开关效果环境
    热门课程:
    400-888-4849
    • 学校新闻

    jQuery和PHP打造功能开关效果

    在开发项目中,我们会经常碰到需要及时开启某项功能的情况,*Ajax实现实时开启和关闭功能,无疑增强了用户体验。本文以360安全卫士的木马防火墙开关为背景,使用PHP、jquery、MYSQL实现了及时开启和关闭产品功能的WEB应用。

    查看演示DEMO

    准备工作

    为了更好的演示本例,我们需要一个数据表,记录需要的功能说明及开启状态,表结构如下:

    
    
    1. CREATE TABLE `pro` (  
    2.   `id` int(11) NOT NULL auto_increment,  
    3.   `title` varchar(50) NOT NULL,  
    4.   `description` varchar(200) NOT NULL,  
    5.   `status` tinyint(1) NOT NULL default '0',  
    6.   PRIMARY KEY  (`id`)  
    7. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;  

    你可以向表中pro插入几条数据。

    index.php

    我们要在页面显示相关功能列表,使用PHP读取数据表,并以列表的形式展示。

    
    
    1. <?php   
    2.    require_once('connect.php'); //连接数据库 
    3.    $query=mysql_query("select * from pro order by id asc");   
    4.    while ($row=mysql_fetch_array($query)) {   
    5.    ?>   
    6.    < class="list">   
    7.      < class="fun_title">   
    8.         <span rel="<?php echo $row['id'];?>" <?php if($row['status']==1){ ?>   
    9. class="ad_on" title="点击关闭"<?php }else{?>class="ad_off" title="点击开启"<?php }?>></span>   
    10.         <h3><?php echo $row['title']; ?></h3>   
    11.      </>   
    12.      <p><?php echo $row['description'];?></p>   
    13.    </>   
    14.  <?php } ?>   

    文豆PHP | 文豆PHP|东莞文豆PHP|文豆PHP怎么样 | 东莞文豆PHP教育

    东莞文豆PHP教育团购预约热线:400-888-4849