Home Web Front-end HTML Tutorial 局部动态加载页面_html/css_WEB-ITnose

局部动态加载页面_html/css_WEB-ITnose

Jun 21, 2016 am 09:15 AM

    不知道各位小伙伴在做前端页面的时候,会不会跟我有一样的经历,整个系统大体上是需要一个整体框架的,只有局部需要不时地刷新。话不多说,以下就是我要实现的效果图。

显然,我用红色边框框起的的地方是整个项目页面都需要有的,而黄色的两个边框的,有些页面采用了同样的样式,有些改变上面黄色边框,有些改变下面黄色边框。

于是,我就想到了用Ajax动态请求其他页面中的内容。这样及不会让index页面的代码内容过多,也可以让几个样式相同的板块统一样式,请求同一页面,省事。

首先呢,我在主页面留了两个空白的div,也就是那两个黄色边框所在的位置。

<div id="navBoxContent">    <div id="boxButton">        </div>    <div id="mainContent">    </div></div>
Copy after login

上面黄色边框的内容呢,放在另外一个right1.html文件中。以下是right1.html中的内容。

<ul style="margin-left: 30px">   <li><div class="but" id="add"><img src="/static/imghw/default1.png"  data-src="images/index/add.png"  class="lazy"   alt="添加"/></div></li>   <li><div class="but" id="edit"><img src="/static/imghw/default1.png"  data-src="images/index/edit.png"  class="lazy"   alt="修改"/></div></li>   <li><div class="but" id="del" onclick="del()"><img src="/static/imghw/default1.png"  data-src="images/index/del.png"  class="lazy"   alt="删除"/></div></li></ul><div id="search"><input type="text" placeholder="请输入关键字"><img src="/static/imghw/default1.png"  data-src="images/index/search.png"  class="lazy"   alt="搜索"/></div>
Copy after login

下面黄色边框的内容呢,放在table.html中。表格的样式采用了easyui中的datagrid。

<table id="dg"    style="max-width:90%" data-options="                                    rownumbers:false,                                    singleSelect:true,                                    autoRowHeight:false,                                    pagination:true,                                    resizeHandle:'right'">    <thead>    <tr>    </tr>    </thead></table>
Copy after login

对以上right1.html和table.html中的css样式控制呢,可以直接放在index中的统一css样式文件中。

接下来就是js的动态请求了。

$(function(){    //企业信息 用户管理   $("#companyInformation").click(function(){        $.ajax({//按钮栏显示            url:"right1.html",            dataType:"html",            type:"get",            success:function(data){                $("#boxButton").html(data);                $("#boxButton").css({"height":"50px","background":"url('images/index/search_bg.png')"})            }        });       $.ajax({//表格显示           url:"table.html",           dataType:"html",           type:"get",           success:function(data){               $("#mainContent").html(data);               $("#mainContent").css({"height":"509px"});               $.ajax({                   url:"datagrid_data.json",                   type:"post",                   dataType:"json",                   success:function(data){                       $("#dg").datagrid({                           columns:[data.title]    //动态取标题                       });                       $("#dg").datagrid("loadData",data.rows);  //动态取数据                       $("#dg").datagrid('getPager').pagination({//分页栏下方文字显示                           pageSize: 15,//每页显示的记录条数,默认为10                           pageList:[15,30,45,60],//每页显示几条记录                           beforePageText: '第',//页数文本框前显示的汉字                           afterPageText: '页    共 {pages} 页',                           displayMsg: '当前显示 {from} - {to} 条记录    共 {total} 条记录',                           onBeforeRefresh:function(){                               $(this).pagination('loading');//正在加载数据中...                               $(this).pagination('loaded'); //数据加载完毕                           }                       })                   }               });           }       });    });});
Copy after login

当然,我前面也说了,我很多栏目的页面可能会是请求同一个页面。那么怎么给两个按钮添加同一个事件呢。在这里,我采用了这样的一种方式:

$("#companyInformation").add($("#userManage")).click(function(){.....});
Copy after login

也就是js的add方法,这样,当点击id名为companyInformation和userManage的menu时都会加载这个表格页面。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles