代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
发一个数据过滤的代码,很简单,有用的着的拿去
时间:2022-04-20 09:00:02 | 栏目:
JavaScript代码
| 点击:次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from url=(0058)http://www.barelyfitz.com/projects/filterlist/example.html --> <HTML><HEAD><TITLE>Filterlist Example</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <script type="text/javascript"> <!-- /*==================================================* $Id: filterlist.js,v 1.3 2003/10/08 17:13:49 pat Exp $ Copyright 2003 Patrick Fitzgerald http://www.barelyfitz.com/webdesign/articles/filterlist/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ?-1307 USA *==================================================*/ function filterlist(selectobj) { //================================================== // PARAMETERS //================================================== // HTML SELECT object // For example, set this to document.myform.myselect this.selectobj = selectobj; // Flags for regexp matching. // "i" = ignore case; "" = do not ignore case // You can use the set_ignore_case() method to set this this.flags = 'i'; // Which parts of the select list do you want to match? this.match_text = true; this.match_value = false; // You can set the hook variable to a function that // is called whenever the select list is filtered. // For example: // this.hook = function() { //alert()} // Flag for debug alerts // Set to true if you are having problems. this.show_debug = false; //================================================== // METHODS //================================================== //-------------------------------------------------- this.init = function() { // This method initilizes the object. // This method is called automatically when you create the object. // You should call this again if you alter the selectobj parameter. if (!this.selectobj) return this.debug('selectobj not defined'); if (!this.selectobj.options) return this.debug('selectobj.options not defined'); // Make a copy of the select list options array this.optionscopy = new Array(); if (this.selectobj && this.selectobj.options) { for (var i=0; i < this.selectobj.options.length; i++) { // Create a new Option this.optionscopy[i] = new Option(); // Set the text for the Option this.optionscopy[i].text = selectobj.options[i].text; // Set the value for the Option. // If the value wasn't set in the original select list, // then use the text. if (selectobj.options[i].value) { this.optionscopy[i].value = selectobj.options[i].value; } else { this.optionscopy[i].value = selectobj.options[i].text; } } } } //-------------------------------------------------- this.reset = function() { // This method resets the select list to the original state. // It also unselects all of the options. this.set(''); } //-------------------------------------------------- this.set = function(pattern) { // This method removes all of the options from the select list, // then adds only the options that match the pattern regexp. // It also unselects all of the options. var loop=0, index=0, regexp, e; if (!this.selectobj) return this.debug('selectobj not defined'); if (!this.selectobj.options) return this.debug('selectobj.options not defined'); // Clear the select list so nothing is displayed this.selectobj.options.length = 0; // Set up the regular expression. // If there is an error in the regexp, // then return without selecting any items. try { // Initialize the regexp regexp = new RegExp(pattern, this.flags); } catch(e) { // There was an error creating the regexp. // If the user specified a function hook, // call it now, then return if (typeof this.hook == 'function') { this.hook(); } return; } // Loop through the entire select list and // add the matching items to the select list for (loop=0; loop < this.optionscopy.length; loop++) { // This is the option that we're currently testing var option = this.optionscopy[loop]; // Check if we have a match if ((this.match_text && regexp.test(option.text)) || (this.match_value && regexp.test(option.value))) { // We have a match, so add this option to the select list // and increment the index this.selectobj.options[index++] = new Option(option.text, option.value, false); } } // If the user specified a function hook, // call it now if (typeof this.hook == 'function') { this.hook(); } } //-------------------------------------------------- this.set_ignore_case = function(value) { // This method sets the regexp flags. // If value is true, sets the flags to "i". // If value is false, sets the flags to "". if (value) { this.flags = 'i'; } else { this.flags = ''; } } //-------------------------------------------------- this.debug = function(msg) { if (this.show_debug) { alert('FilterList: ' + msg); } } //================================================== // Initialize the object //================================================== this.init(); } //--> </script> <META content="MSHTML 6.00.2900.3020" name=GENERATOR></HEAD> <BODY> <H1>Filterlist Example</H1> <FORM name=myform action=""><SELECT size=5 name=myselect> <OPTION>Keanu Reeves<OPTION>Laurence Fishburne<OPTION>Monica Bellucci<OPTION>Daniel Bernhardt<OPTION>Nona Gaye<OPTION>Lachy Hulme<OPTION>Nathaniel Lees<OPTION>Harry J. Lennix<OPTION>Matt McColm<OPTION>Carrie-Anne Moss<OPTION>Collin Chou<OPTION>Genevieve O'Reilly<OPTION>Harold Perrineau Jr.<OPTION>Jada Pinkett Smith<OPTION>Adrian Rayment<OPTION>Neil Rayment<OPTION>Bruce Spence<OPTION>Hugo Weaving<OPTION>Lambert Wilson<OPTION>Anthony Wong</OPTION></SELECT> <SCRIPT type=text/javascript> <!-- var myfilter = new filterlist(document.myform.myselect); //--> </SCRIPT> <P>Filter: <A title="Clear the filter" href="javascript:myfilter.reset()">Clear</A> <A title="Show items starting with A" href="javascript:myfilter.set('^A')">A</A> <A title="Show items starting with B" href="javascript:myfilter.set('^B')">B</A> <A title="Show items starting with C" href="javascript:myfilter.set('^C')">C</A> <A title="Show items starting with D" href="javascript:myfilter.set('^D')">D</A> <A title="Show items starting with E" href="javascript:myfilter.set('^E')">E</A> <A title="Show items starting with F" href="javascript:myfilter.set('^F')">F</A> <A title="Show items starting with G" href="javascript:myfilter.set('^G')">G</A> <A title="Show items starting with H" href="javascript:myfilter.set('^H')">H</A> <A title="Show items starting with I" href="javascript:myfilter.set('^I')">I</A> <A title="Show items starting with J" href="javascript:myfilter.set('^J')">J</A> <A title="Show items starting with K" href="javascript:myfilter.set('^K')">K</A> <A title="Show items starting with L" href="javascript:myfilter.set('^L')">L</A> <A title="Show items starting with M" href="javascript:myfilter.set('^M')">M</A> <A title="Show items starting with N" href="javascript:myfilter.set('^N')">N</A> <A title="Show items starting with O" href="javascript:myfilter.set('^O')">O</A> <A title="Show items starting with P" href="javascript:myfilter.set('^P')">P</A> <A title="Show items starting with Q" href="javascript:myfilter.set('^Q')">Q</A> <A title="Show items starting with R" href="javascript:myfilter.set('^R')">R</A> <A title="Show items starting with S" href="javascript:myfilter.set('^S')">S</A> <A title="Show items starting with T" href="javascript:myfilter.set('^T')">T</A> <A title="Show items starting with U" href="javascript:myfilter.set('^U')">U</A> <A title="Show items starting with V" href="javascript:myfilter.set('^V')">V</A> <A title="Show items starting with W" href="javascript:myfilter.set('^W')">W</A> <A title="Show items starting with X" href="javascript:myfilter.set('^X')">X</A> <A title="Show items starting with Y" href="javascript:myfilter.set('^Y')">Y</A> <A title="Show items starting with Z" href="javascript:myfilter.set('^Z')">Z</A> <P><!-- Note: if you have a very large select list, you should deactivate the real-time filtering on the INPUT field below - remove the onKeyUp attribute. -->Filter by regular expression:<INPUT onkeyup=myfilter.set(this.value) name=regexp> <INPUT onclick=myfilter.set(this.form.regexp.value) type=button value=Filter> <INPUT onclick="myfilter.reset();this.form.regexp.value=''" type=button value=Clear> <INPUT onclick=myfilter.set_ignore_case(!this.checked) type=checkbox name=toLowerCase> Case-sensitive </FORM></P></BODY></HTML>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
兼容浏览器的js事件绑定函数(详解)
相关文章
10-19
javascript上下左右定时滚动插件
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长