在实现程序的修改模块时,要在页面端检查用户是否修改过数据,以便提醒用户及时保存修改后的数据。 实现要求: 判断用户是否修改了输入的内容,要能判断input中的checkbox,text,radio等,不知道会多少个input,也不知道input的ID和name,要在客户端判断是否修改,不能产
生提交。还要同时满足IE和firefox两种环境。也要支持master和content页的使用。 解决方案; 处理思路:在页面加载时记录所有的input的值或状态,如果要求在用户进行修改操作时立即调整控件状态,则在数据区div上的onclick和onkeypress事件里调用检查数据
是否改变的函数,并设置相应控件的状态(用ha_setch())。如果是在提交或用户手动控制检查过程时,则在相应的操作事件中调用检查数据是否改变(例在button的onclick
()中使用ha_checkin()控制提交)。 以下是实现代码 var ha_last=new Array;//定义一个全局的空对象,存放所有的初始值。 function ha_get()//读取初始值 { var ha_input = document.getElementsByTagName("input"); for (var i=0;i<ha_input.length;i++) { if (ha_input[i].type=="password"){ ha_last.push(ha_input[i].value);}//根本页面需要设置type的值和对象属性 if (ha_input[i].type=="radio") {ha_last.push(ha_input[i].checked);}//要保证检查的范围是否准确 } } window.onload=ha_get;//绑定读取初始值的函数 function ha_checkin()//检查新的输入值和初始值是否相等。返回判断结果。true为没有发生修改,false为有修改。 { var ha_now=new Array; var ha_input = document.getElementsByTagName("input"); for (var i=0;i<ha_input.length;i++) { if (ha_input[i].type=="password"){ ha_now.push(ha_input[i].value);}//根本页面需要设置type的值和对象属性。 if (ha_input[i].type=="radio") {ha_now.push(ha_input[i].checked);}//也要保证和ha_get()中检查的标签相一致 } if (ha_now.toString()==ha_last.toString())//没修改 {return true;} else//有修改 {return false;} } function ha_setch(){//设置相应的控件状态 if (ha_checkin())//没有变化 //改变控件的显示和功能状态 else//有变化 //改变控件的显示和功能状态 }
做了适当的修改。最后在button里面onclick直接调用
var ha_last=new Array;//定义一个全局的空对象,存放所有的初始值。 function ha_get()//读取初始值 { var ha_input = document.getElementsByTagName("input"); ha_last.push($("#select").val());//采用jquery获取select 选择的值 for (var i=0;i<ha_input.length;i++) { if (ha_input[i].type=="text"){ ha_last.push(ha_input[i].value);}//根本页面需要设置type的值和对象属性 } } window.onload=ha_get;//绑定读取初始值的函数 function ha_checkin(action)//检查新的输入值和初始值是否相等。返回判断结果。true为没有发生修改,false为有修改。 { if(action=="update"){ var ha_now=new Array; var ha_input = document.getElementsByTagName("input"); ha_now.push($("#select").val()); for (var i=0;i<ha_input.length;i++) { if (ha_input[i].type=="text"){ ha_now.push(ha_input[i].value);}//根本页面需要设置type的值和对象属性。 } if (ha_now.toString()==ha_last.toString())//没修改 { alert("没有修改"); return false; } else//有修改 { // return true; } } }
来自:http://www.javaeye.com/topic/304818
jQuery 是我最喜欢的一个Javascript框架,下表中包含了240+可以为jQuery爱好者们使用的插件。我断定一定还有下表没有包括的,如果你还知道其他的好东西,欢迎与大家分享。
Ajax File Upload jQUploader Multiple File Upload plugin jQuery File Style Styling an input type file Progress Bar Plugin
jQuery Validation Auto Help Simple jQuery form validation jQuery XAV - form validations jQuery AlphaNumeric Masked Input TypeWatch Plugin Text limiter for form fields Ajax Username Check with jQuery
jQuery Combobox jQuery controlled dependent (or Cascadign) Select List Multiple Selects Select box manipulation Select Combo Plugin jQuery - LinkedSelect Auto-populate multiple select boxes Choose Plugin (Select Replacement)
jQuery Form Plugin jQuery-Form jLook Nice Forms jNice Ping Plugin Toggle Form Text ToggleVal jQuery Field Plugin jQuery Form’n Field plugin jQuery Checkbox manipulation jTagging jQuery labelcheck Overlabel 3 state radio buttons ShiftCheckbox jQuery Plugin Watermark Input jQuery Checkbox (checkboxes with imags) jQuery SpinButton Control jQuery Ajax Form Builder jQuery Focus Fields jQuery Time Entry
jQuery UI Datepicker jQuery date picker plugin jQuery Time Picker Time Picker ClickPick TimePicker Farbtastic jQuery Color Picker Plugin Color Picker by intelliance.fr
jQuery Star Rating Plugin jQuery Star Rater Content rater with asp.net, ajax and jQuery Half-Star Rating Plugin
Autocomplete Box jQuery Suggest jQuery Autocomplete jQuery Autocomplete Mod jQuery Autocomplete by AjaxDaddy jQuery Autocomplete Plugin with HTML formatting jQuery Autocompleter AutoCompleter (Tutorial with PHP&MySQL) quick Search jQuery Plugin
jTagEditor WYMeditor jQuery jFrame Jeditable - edit in place plugin for jQuery jQuery editable jQuery Disable Text Select Plugin Edit in Place with Ajax using jQuery jQuery Plugin - Another In-Place Editor TableEditor tEditable - in place table editing for jQuery
jMedia - accessible multi-media embedding JBEdit - Ajax online Video Editor jQuery MP3 Plugin jQuery Media Plugin jQuery Flash Plugin Embed QuickTime SVG Integration jQuery Multimedia Portfolio jQuery YouTube Plugin
ThickBox jQuery lightBox plugin jQuery FancyBox jQuery Multimedia Portfolio jQuery Image Strip jQuery slideViewer jQuery jqGalScroll 2.0 jQuery - jqGalViewII jQuery - jqGalViewIII jQuery Photo Slider jQuery Thumbs - easily create thumbnails jQuery jQIR Image Replacement jCarousel Lite jQPanView jCarousel Interface Imagebox Image Gallery using jQuery, Interface & Reflactions simple jQuery Gallery jQuery Gallery Module EO Gallery jQuery ScrollShow jQuery Cycle Plugin jQuery Flickr jQuery Lazy Load Images Plugin Zoomi - Zoomable Thumbnails jQuery Crop - crop any image on the fly Image Reflection
jQuery Plugin googlemaps jMaps jQuery Maps Framework jQmaps jQuery & Google Maps jQuery Maps Interface forr Google and Yahoo maps jQuery J Maps - by Tane Piper
Tetris with jQuery jQuery Chess Mad Libs Word Game jQuery Puzzle jQuery Solar System (not a game but awesome jQuery Stuff) jQuery Memory
UI/Tablesorter jQuery ingrid jQuery Grid Plugin Table Filter - awesome! TableEditor jQuery Tree Tables Expandable “Detail” Table Rows Sortable Table ColdFusion Costum Tag with jQuery UI jQuery Bubble TableSorter Scrollable HTML Table jQuery column Manager Plugin jQuery tableHover Plugin jQuery columnHover Plugin jQuery Grid TableSorter plugin for jQuery tEditable - in place table editing for jQuery jQuery charToTable Plugin jQuery Grid Column Sizing jQuery Grid Row Sizing
Flot jQuery Wizard Plugin jQuery Chart Plugin Bar Chart Accessible Charts using Canvas and jQuery
jQuery Corner jQuery Curvy Corner Nifty jQuery Corner Transparent Corners jQuery Corner Gallery Gradient Plugin
jQuery Spoiler plugin Text Highlighting Disable Text Select Plugin jQuery Newsticker Auto line-height Plugin Textgrad - a text gradient plugin LinkLook - a link thumbnail preview pager jQuery Plugin shortKeys jQuery Plugin jQuery Biggerlink jQuery Ajax Link Checker Chili jQuery code highlighter plugin jScroller
jQuery Plugin - Tooltip jTip - The jQuery Tool Tip clueTip BetterTip Flash Tooltips using jQuery ToolTip
jQuery Tabs Plugin - awesome! [demo nested tabs ] another jQuery nested Tab Set example (based on jQuery Tabs Plugin) jQuery idTabs jdMenu - Hierarchical Menu Plugin for jQuery jQuery SuckerFish Style jQuery Plugin Treeview treeView Basic FastFind Menu Sliding Menu Lava Lamp jQuery Menu jQuery iconDock jVariations Control Panel ContextMenu plugin clickMenu CSS Dock Menu jQuery Pop-up Menu Tutorial Sliding Menu
jQuery Plugin Accordion jQuery Accordion Plugin Horizontal Way haccordion - a simple horizontal accordion plugin for jQuery Horizontal Accordion by portalzine.de HoverAccordion Accordion Example from fmarcia.info jQuery Accordion Example jQuery Demo - Expandable Sidebar Menu Sliding Panels for jQuery jQuery ToggleElements Coda Slider jCarousel Accesible News Slider Plugin Showing and Hiding code Examples jQuery Easing Plugin jQuery Portlets AutoScroll Innerfade CodaSlider
UI/Draggables EasyDrag jQuery Plugin jQuery Portlets jqDnR - drag, drop resize Drag Demos
XSLT Plugin jQuery Ajax call and result XML parsing xmlObjectifier - Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite - multiple Dom updates RSS/ATOM Feed Parser Plugin jQuery Google Feed Plugin
Wresize - IE Resize event Fix Plugin jQuery ifixpng jQuery pngFix Link Scrubber - removes the dotted line onfocus from links jQuery Perciformes - the entire suckerfish familly under one roof Background Iframe QinIE - for proper display of Q tags in IE jQuery Accessibility Plugin jQuery MouseWheel Plugin
jQuery Impromptu jQuery Confirm Plugin jqModal SimpleModal
jQuery Style Switcher JSS - Javascript StyleSheets jQuery Rule - creation/manipulation of CSS Rules jPrintArea
FlyDOM jQuery Dimenion Plugin jQuery Loggin Metadata - extract metadata from classes, attributes, elements Super-tiny Client-Side Include Javascript jQuery Plugin Undo Made Easy with Ajax JHeartbeat - periodically poll the server Lazy Load Plugin Live Query jQuery Timers jQuery Share it - display social bookmarking icons jQuery serverCookieJar jQuery autoSave jQuery Puffer jQuery iFrame Plugin Cookie Plugin for jQuery jQuery Spy - awesome plugin Effect Delay Trick jQuick - a quick tag creator for jQuery Metaobjects elementReady