不知道各位小伙伴在做前端页面的时候,会不会跟我有一样的经历,整个系统大体上是需要一个整体框架的,只有局部需要不时地刷新。话不多说,以下就是我要实现的效果图。
显然,我用红色边框框起的的地方是整个项目页面都需要有的,而黄色的两个边框的,有些页面采用了同样的样式,有些改变上面黄色边框,有些改变下面黄色边框。
于是,我就想到了用Ajax动态请求其他页面中的内容。这样及不会让index页面的代码内容过多,也可以让几个样式相同的板块统一样式,请求同一页面,省事。
首先呢,我在主页面留了两个空白的div,也就是那两个黄色边框所在的位置。
<div id="navBoxContent"> <div id="boxButton"> </div> <div id="mainContent"> </div></div>
上面黄色边框的内容呢,放在另外一个right1.html文件中。以下是right1.html中的内容。
<ul style="margin-left: 30px"> <li><div class="but" id="add"><img src="/static/imghwm/default1.png" data-src="images/index/add.png" class="lazy" alt="添加"/></div></li> <li><div class="but" id="edit"><img src="/static/imghwm/default1.png" data-src="images/index/edit.png" class="lazy" alt="修改"/></div></li> <li><div class="but" id="del" onclick="del()"><img src="/static/imghwm/default1.png" data-src="images/index/del.png" class="lazy" alt="删除"/></div></li></ul><div id="search"><input type="text" placeholder="请输入关键字"><img src="/static/imghwm/default1.png" data-src="images/index/search.png" class="lazy" alt="搜索"/></div>
下面黄色边框的内容呢,放在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>
对以上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'); //数据加载完毕 } }) } }); } }); });});
当然,我前面也说了,我很多栏目的页面可能会是请求同一个页面。那么怎么给两个按钮添加同一个事件呢。在这里,我采用了这样的一种方式:
$("#companyInformation").add($("#userManage")).click(function(){.....});
也就是js的add方法,这样,当点击id名为companyInformation和userManage的menu时都会加载这个表格页面。

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
