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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

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.

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.

See all articles