Home Database Mysql Tutorial Web实用技巧总结

Web实用技巧总结

Jun 07, 2016 pm 03:36 PM
web how Practical Tips Summarize ask page

1、如何每次请求Web页面都取最新版本,而不是浏览器缓存中的页面 l 问题:浏览器中可以设定缓存选项来设置是否使用页面缓存,所以没法强制用户设定所有的Web页面都不使用缓存。 l 解决方法:在页面的HEAD标记中添加下面的标记,以保证该页面不缓存,每次请求

1、如何每次请求Web页面都取最新版本,而不是浏览器缓存中的页面

l  问题:浏览器中可以设定缓存选项来设置是否使用页面缓存,所以没法强制用户设定所有的Web页面都不使用缓存。

l  解决方法:在页面的

标记中添加下面的标记,以保证该页面不缓存,每次请求都取最新版本。

  

l  浏览器缓存设置是针对所有页面的,而这种设置方法是针对特定单个页面的,会覆盖浏览器缓存设置。

2、在使用window.showModalDialog()方法打开窗口中,如何提交表单不会弹出新窗口?

l  问题:首先window.showModalDialog()只在IE浏览器中有效。在使用window.showModalDialog()方法打开窗口中提交表单时,IE浏览器默认情况在新窗口中显示结果页面。

l  解决方法:在页面的

标记中添加下面的标记,指定基本目标窗口为_self。这样,提交表单时,就会在当前窗口中显示结果页面。

 

3、双表头固定的数据列表中,滚动条同步移动的实现

l  问题:Web中单表头固定的数据列表使用比较多,其滚动条移动的实现很简单,只要使用

标记,设置其的样式就可以了。但有时也需要使用双表头固定的数据列表,典型的例子就是人员的日程安排。

l  解决方法:分别用三个

标记包含上表头(topheader),左表头(leftheader)和数据内容(content),只有content有滚动条;当移动滚动条时(产生onscroll事件),设置topheader的scrollLeft属性以及leftheader 的scrollTop属性,使其和content保持一致。

l  下面是一个实现例子的核心代码片断,做一下简单说明,源代码可以在这里下载。

function hasAttribute(object, attrName) {

if (typeof object !== "object" && typeof object !== "string") {

return false;

}

return attrName in object;

}

function syncScroll(topId, leftId, contentId) {

var topHeader = document.getElementById(topId);

var leftHeader = document.getElementById(leftId);

var content = document.getElementById(contentId);

if (topHeader && hasAttribute(topHeader, 'scrollLeft') && content && hasAttribute(content, 'scrollLeft')) {

topHeader.scrollLeft=content.scrollLeft;

}

if (leftHeader && hasAttribute(leftHeader, 'scrollTop') && content && hasAttribute(content, 'scrollTop')) {

leftHeader.scrollTop=content.scrollTop;

}

}

l  先来看三个

标记的样式:

?  overflow: scroll表示当

标记中的内容溢出时可以滚动

?  topheader和leftheader的overflow-x及overflow-y属性设置为hidden,表示溢出时不显示滚动条,而content设置为auto

?  content的width值比topheader的大16px,而height值比leftheader的大17px;这是为滚动条预留的(滚动条大概16-17px,根据具体   情况微调)

?  word-break: break-all用来保证数据过长时自动换行,以免将单元格宽度撑大而错位

l  topheader和content内部包含的

的width设置为绝对大小,并大于对应
的width,以便出现水平滚动条

syncScroll()函数在onscroll事件触发时调用,使topheader的scrollLeft属性以及leftheader 的scrollTop属性和content的保持同步

l  上面的例子个静态页面,在实际应用中通常是动态页面,需要注意以下一些方面:

?  显示的列数不定时(例如每个月的天数有所不同),需要动态计算

的width值

?  当content内部包含的

的width值

?  同样,当content内部包含的

的height值

?  word-break: break-all保证了单元格宽度不会撑大;但当单元格内容显示不下时,会自动撑大宽度,所以当表格的行距不同时,要动态计算以决定是否要出垂直滚动条,这个要麻烦一些

4、全角半角字符混合输入的处理

l  问题1:输入长度的验证,例如输入内容在数据库中是40字节,所以输入长度不能超过40字节;而JavaScript中的String.length获得的是字符个数。

l  解决方法:通常全角字符为2字节,而半角字符为1字节;这样String.length获得的长度相当于将全角字符作为1字节处理,所以再加上全角字符的个数就是字节数。考虑到escape()函数处理的字符串中,全角字符都转换成%uXXXX的Unicode形式,可以由此统计出字符串中的全角字符个数。

l  下面的JavaScript代码扩展了String对象,用来获取字符串的字节数

String.prototype.getBytesLength = function () {

return this.length + (escape(this).split("%u").length - 1);

};

l  问题2:由于显示空间有限,要求显示内容按指定长度(字节数)截取,这里有全角字符的前一个字节在指定长度范围里的问题。

l  解决方法:从字符串后端开始,逐个删除字符,直到字符串字节数

l  下面的JavaScript代码扩展了String对象,实现了上面的截取方法

String.prototype.removeCharAt = function (index) {

var retStr = this;

if (index

if (index === 0) {

retStr = this.substring(1);

} else {

if (index == this.length - 1) {

retStr = this.substring(0, this.length - 1);

} else {

retStr = this.substring(0, index) + this.substring(index + 1);

}

}

}

return retStr;

};

String.prototype.intercept = function (length) {

var s = this;

var len = s.getBytesLength();

while (len > length) {

s = s.removeCharAt(s.length - 1);

len = s.getBytesLength();

}

return s;

};

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

Troubleshooting Tomcat 404 Errors: Quick and Practical Tips Troubleshooting Tomcat 404 Errors: Quick and Practical Tips Dec 28, 2023 am 08:05 AM

Practical Tips to Quickly Solve Tomcat404 Errors Tomcat is a commonly used JavaWeb application server and is often used when developing and deploying JavaWeb applications. However, sometimes we may encounter a 404 error from Tomcat, which means that Tomcat cannot find the requested resource. This error can be caused by multiple factors, but in this article, we will cover some common solutions and tips to help you resolve Tomcat 404 errors quickly. Check URL path

Summarize the usage of system() function in Linux system Summarize the usage of system() function in Linux system Feb 23, 2024 pm 06:45 PM

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

Practical tips for efficiently solving Java large file reading exceptions Practical tips for efficiently solving Java large file reading exceptions Feb 21, 2024 am 10:54 AM

Practical tips for efficiently resolving large file read exceptions in Java require specific code examples. Overview: When processing large files, Java may face problems such as memory overflow and performance degradation. This article will introduce several practical techniques to effectively solve Java large file reading exceptions, and provide specific code examples. Background: When processing large files, we may need to read the file contents into memory for processing, such as searching, analyzing, extracting and other operations. However, when the file is large, the following problems are often encountered: Memory overflow: trying to copy the entire file at once

How to quickly refresh a web page? How to quickly refresh a web page? Feb 18, 2024 pm 01:14 PM

Page refresh is very common in our daily network use. When we visit a web page, we sometimes encounter some problems, such as the web page not loading or displaying abnormally, etc. At this time, we usually choose to refresh the page to solve the problem, so how to refresh the page quickly? Let’s discuss the shortcut keys for page refresh. The page refresh shortcut key is a method to quickly refresh the current web page through keyboard operations. In different operating systems and browsers, the shortcut keys for page refresh may be different. Below we use the common W

How to deal with the problem that Laravel page cannot display CSS correctly How to deal with the problem that Laravel page cannot display CSS correctly Mar 10, 2024 am 11:33 AM

"Methods to handle Laravel pages that cannot display CSS correctly, need specific code examples" When using the Laravel framework to develop web applications, sometimes you will encounter the problem that the page cannot display CSS styles correctly, which may cause the page to render abnormal styles. Affect user experience. This article will introduce some methods to deal with the failure of Laravel pages to display CSS correctly, and provide specific code examples to help developers solve this common problem. 1. Check the file path. First check the path of the CSS file.

What are web standards? What are web standards? Oct 18, 2023 pm 05:24 PM

Web standards are a set of specifications and guidelines developed by W3C and other related organizations. It includes standardization of HTML, CSS, JavaScript, DOM, Web accessibility and performance optimization. By following these standards, the compatibility of pages can be improved. , accessibility, maintainability and performance. The goal of web standards is to enable web content to be displayed and interacted consistently on different platforms, browsers and devices, providing better user experience and development efficiency.

How to implement page jump in 3 seconds: PHP Programming Guide How to implement page jump in 3 seconds: PHP Programming Guide Mar 25, 2024 am 10:42 AM

Title: Implementation method of page jump in 3 seconds: PHP Programming Guide In web development, page jump is a common operation. Generally, we use meta tags in HTML or JavaScript methods to jump to pages. However, in some specific cases, we need to perform page jumps on the server side. This article will introduce how to use PHP programming to implement a function that automatically jumps to a specified page within 3 seconds, and will also give specific code examples. The basic principle of page jump using PHP. PHP is a kind of

See all articles