Javascript

浏览模式: 标准 | 列表 | 图文
推荐一个Jquery插件:autoComplete

推荐一个Jquery插件:autoComplete

我就不翻译了……

这些东西也不复杂。

Copy网站开始……黑黑

Dependencies

Known issues:

  • When completing multiple values, only the last value can be edited with the autocomplete help
  • mustMatch option is broken (mostly fixed in latest revision)
  • default browser autocomplete displays a long list of values scrollable, that isn’t supported yet

Recent changes

Documentation

Autocompletition of input elements is a very helpful tool to guide users in entering the right value. That value can come from a (big) list of possible values or it may consist of values the user has entered before. This plugin makes it easy for a developer to setup autocomplete for text inputs and textareas.

Setup
First step in setting up autocomplete is to decide what kind of data is provided. To autocomplete a few dozen possible values, it is a good idea to provide local data. The data is loaded only once and then cached, providing a very responsive interface.
If the data can consist of hundreds, thousands or even millions of rows, the searching and filtering must be done where performance won’t suffer, in most cases a relational database (eg. MySQL). The plugin will request the rows for the entered value, displaying only a subset of all possible values.
For local autocomplete, just pass the data as an array to the autocomplete plugin. For remote autocomplete, specify an URL pointing to the resource providing the data. The plugin then requests data with a “q” parameter containing the current search value.

API

  • autocomplete( String|Array urlOrData, Map options ) returns jQuery
    Provide autocomplete for text-inputs or textareas.

    Depends on dimensions plugin’s offset method for correct positioning of the select box and bgiframe plugin
    to fix IE’s problem with selects.

    Options

    • inputClass (String): This class will be added to the input box. Default: “ac_input”
    • resultsClass (String): The class for the UL that will contain the result items (result items are LI elements). Default: “ac_results”
    • loadingClass (String): The class for the input box while results are being fetched from the server. Default: “ac_loading”
    • minChars (Number): The minimum number of characters a user has to type before the autocompleter activates. Default: 1
    • delay (Number): The delay in milliseconds the autocompleter waits after a keystroke to activate itself. Default: 400 for remote, 10 for local
    • cacheLength (Number): The number of backend query results to store in cache. If set to 1 (the current result), no caching will happen. Do not set below 1. Default: 10
    • matchSubset (Boolean): Whether or not the autocompleter can use a cache for more specific queries. This means that all matches of “foot” are a subset of all matches for “foo”. Usually this is true, and using this options decreases server load and increases performance. Only useful with cacheLength settings bigger then one, like 10. Default: true
    • matchCase (Boolean): Whether or not the comparison is case sensitive. Only important only if you use caching. Default: false
    • matchContains (Boolean): Whether or not the comparison looks inside (i.e. does “ba” match “foo bar”) the search results. Only important if you use caching. Don’t mix with autofill. Default: false
    • mustMatch (Booolean): If set to true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box. Default: false
    • extraParams (Object): Extra parameters for the backend. If you were to specify { bar:4 }, the autocompleter would call my_autocomplete_backend.php?q=foo&bar=4 (assuming the input box contains “foo”). Default: {}
    • selectFirst (Boolean): If this is set to true, the first autocomplete value will be automatically selected on tab/return, even if it has not been handpicked by keyboard or mouse action. If there is a handpicked (highlighted) result, that result will take precedence. Default: true
    • formatItem (Function): Provides advanced markup for an item. For each row of results, this function will be called. The returned value will be displayed inside an LI element in the results list. Autocompleter will provide 3 parameters: the results row, the position of the row in the list of results (starting at 1), and the number of items in the list of results. Default: none, assumes that a single row contains a single value.
    • formatResult (Function): Similar to formatResult, but provides the formatting for the value to be put into the input field. Again three arguments: Data, position (starting with one) and total number of data. Default: none, assumes either plain data to use as result or uses the same value as provided by formatItem.
    • multiple (Boolean): Whether to allow more then one autocomplted-value to enter. Default: false
    • multipleSeparator (String): Seperator to put between values when using multiple option. Default: “, “
    • width (Number): Specify a custom width for the select box. Default: width of the input element
    • autoFill (Boolean): Fill the textinput while still selecting a value, replacing the value if more is type or something else is selected. Default: false
    • max (Number): Limit the number of items in the select box. Is also send as a “limit” parameter with a remote request. Default: 10

    Example:

    Autocomplete a text-input with remote data. For small to giant datasets.

    When the user starts typing, a request is send to the specified backend (”my_autocomplete_backend.php”),
    with a GET parameter named q that contains the current value of the input box and a paremeter “limit” with
    the value specified for the max option.

    A value of “foo” would result in this request url: my_autocomplete_backend.php?q=foo&limit=10

    The result must return with one value on each line. The result is presented in the order
    the backend sends it.

    $("#input_box").autocomplete("my_autocomplete_backend.php");

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a text-input with local data. For small datasets.

    $("#input_box").autocomplete(["Cologne", "Berlin", "Munich"]);

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a text-input with data received via AJAX. For small to medium sized datasets.

    $.getJSON("my_backend.php", function(data) {
      $("#input_box").autocomplete(data);
    });

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a textarea with local data (for small datasets). Once the user chooses one
    value, a separator is appended (by default a comma, see multipleSeparator option) and more values
    are autocompleted.

    $("#mytextarea").autocomplete(["Cologne", "Berlin", "Munich"], {
     multiple: true
    });

    HTML:

    <textarea id="mytextarea" />
  • result( Function handler ) returns jQuery
    Handle the result of a search event. Is executed when the user selects a value or a
    programmatic search event is triggered (see search()).

    You can add and remove (using unbind(”result”)) this event at any time.

    Example:

    Bind a handler to the result event to display the selected value in a #result element.
    The first argument is a generic event object, in this case with type “result”.
    The second argument refers to the selected data, which can be a plain string value or an array or object.
    The third argument is the formatted value that is inserted into the input field.

    jQuery('input#suggest').result(function(event, data, formatted) {
      jQuery("#result").html( !data ? "No match!" : "Selected: " + formatted);
    });
  • search( ) returns jQuery
    Trigger a search event. See result(Function) for binding to that event.

    A search event mimics the same behaviour as when the user selects a value from
    the list of autocomplete items. You can use it to execute anything that does something
    with the selected value, beyond simply putting the value into the input and submitting it.

    Example:

    Triggers a search event.

    jQuery('input#suggest').search();

jQuery一些插件的链接[转]

文件上传(File upload)JQuery_001

Ajax File Upload.
jQUploader.
Multiple File Upload plugin.
jQuery File Style.
Styling an input type file.
Progress Bar Plugin.

表单验证(Form Validation)

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.

表单-选取框(Form - Select Box stuff)

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).

表单基本、输入框、选择框等(Form Basics, Input Fields, Checkboxes etc.)

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.

时间、日期和颜色选取(Time, Date and Color Picker)

jQuery UI Datepicker.
jQuery date picker plugin.
jQuery Time Picker.
Time Picker.
ClickPick.
TimePicker.
Farbtastic jQuery Color Picker Plugin.
Color Picker by intelliance.fr.

投票插件(Rating Plugins)

jQuery Star Rating Plugin.
jQuery Star Rater.
Content rater with asp.net, ajax and jQuery.
Half-Star Rating Plugin.

搜索插件(Search Plugins)

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.

编辑器(Inline Edit & Editors)JQuery_002

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.

多媒体、视频、Flash等(Audio, Video, Flash, SVG, etc)

jMedia - accessible multi-media embedding.
JBEdit - Ajax online Video Editor.
jQuery MP3 Plugin.
jQuery Media Plugin.
jQuery Flash Plugin.
Embed QuickTime.
SVG Integration.

图片(Photos/Images/Galleries)

ThickBox.
jQuery lightBox plugin.
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.

Google地图(Google Map)

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.

游戏(Games)

Tetris with jQuery.
jQuery Chess.
Mad Libs Word Game.
jQuery Puzzle.
jQuery Solar System (not a game but awesome jQuery Stuff).

表格等(Tables, Grids etc.)

UI/Tablesorter.JQuery_003
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.

统计图(Charts, Presentation etc.)

jQuery Wizard Plugin .
jQuery Chart Plugin.
Bar Chart.

边框、圆角、背景(Border, Corners, Background)

jQuery Corner.
jQuery Curvy Corner.
Nifty jQuery Corner.
Transparent Corners.
jQuery Corner Gallery.
Gradient Plugin.

文字和超链接(Text and Links)

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.

鼠标提示(Tooltips)

jQuery Plugin - Tooltip.
jTip - The jQuery Tool Tip.
clueTip.
BetterTip.
Flash Tooltips using jQuery.
ToolTip.

菜单和导航(Menus, Navigations)

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.

http://stilbuero.de/jquery/tabs_3/

幻灯、翻转等(Accordions, Slide and Toggle stuff)

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.

拖放插件(Drag and Drop)

UI/Draggables.
EasyDrag jQuery Plugin.
jQuery Portlets.
jqDnR - drag, drop resize.
Drag Demos.

XML XSL JSON Feeds

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.

浏览器(Browserstuff)

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.

对话框、确认窗口(Alert, Prompt, Confirm Windows)

jQuery Impromptu.
jQuery Confirm Plugin.
jqModal.
SimpleModal.

CSS

jQuery Style Switcher.
JSS - Javascript StyleSheets.
jQuery Rule - creation/manipulation of CSS Rules.
jPrintArea.

DOM、AJAX和其它JQuery插件(DOM, Ajax and other jQuery plugins)

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.

JQuery插件:showMsg

JQuery插件:showMsg

<SCRIPT type=text/javascript>
jQuery.fn.showMsg=function(json)
{
if(json==null)
json={};
var bodyScrollSize=this.getBodyScrollSize();
var bodySize=this.getBodySize();
var left=bodyScrollSize.left;
var top=bodyScrollSize.top;
if(json.autoMiddle!=true)
{
if(json.left)left=left+json.left;
if(json.top)top=top+json.top;
}
else if(json.autoMiddle==true)
{
var _w=this.width();
var _h=this.height();
top=(bodySize.height-_h)/2 + top;
left=(bodySize.width-_w)/2;
}
if(top+this.height()>bodyScrollSize.height)
bodyScrollSize.height=top+this.height();
if(left+this.width()>bodyScrollSize.width)
bodyScrollSize.width=left+this.width();

if(json.coverBody==true)
{
$("<iframe id='jq_effect_backGroundIframe' style='z-index:1;filter:mask();overflow:hidden;border:0px;margin:0; padding:0;position:absolute;width:"+bodyScrollSize.width+"px;height:"+bodyScrollSize.height+"px;top:0px;left:0px' scrolling='auto' frameborder='0' ></iframe>").appendTo("body");
var jqCover=$("<div id='jq_effect_backGroundDiv'></div>");
var _css = { "background-color":json.color==undefined?"#000":json.color, "position":"absolute","overflow":"hidden", "-moz-opacity": "0.75" , "filter":"alpha(opacity=75)","z-index":"2" ,"opacity":"0.75", "top" : "0px" , "left":"0px","width":bodyScrollSize.width,"height":bodyScrollSize.height };
jqCover.css(_css);
jqCover.appendTo("body");
}
if(typeof(json.msg)!="undefined")
this.html(json.msg);
this.css("height","auto");
this.css("position","absolute").css("z-index","100");
this.css("left",left+"px").css("top",top+"px").fadeIn("slow");
if(jQuery.msgShowObj!=undefined)
{
try{jQuery.msgShowObj.fadeOut('slow');}catch(e){};
}
jQuery.msgShowObj=this;
if(typeof(json.callback)!="undefined")
jQuery.msgCallBack=json.callback;
else
jQuery.msgCallBack=null;
jQuery.cc=undefined;
if(json.autoClose!=false)
{
jQuery.cc=window.setTimeout("try{jQuery.msgShowObj.closeMsg();}catch(e){}",json.time==undefined?2000:json.time);
}
return this;
}
jQuery.fn.closeMsg=function()
{
this.fadeOut('slow',jQuery.msgCallBack);
jQuery.msgShowObj=undefined;
$('#jq_effect_backGroundIframe').remove();
$('#jq_effect_backGroundDiv').remove();

return this;
}

jQuery.fn.getBodyScrollSize=function()
{
var bodySL, bodyST, bodySW, bodySH;
if(window.pageXOffset)
{
bodySL=window.pageXOffset;
bodySW=window.innerWidth;
bodyST=window.pageYOffset;
bodySH=window.innerHeight;
}
else if(document.documentElement)
{
bodySL=document.documentElement.scrollLeft;
bodySW=document.documentElement.scrollWidth; //-10
bodyST=document.documentElement.scrollTop;
bodySH=document.documentElement.clientHeight>document.documentElement.scrollHeight?document.documentElement.clientHeight:document.documentElement.scrollHeight;
}
else if(document.body)
{
bodySL=document.body.scrollLeft;
bodySW=document.body.scrollWidth;
bodyST=document.body.scrollTop;
bodySH=document.body.clientHeight>document.body.scrollHeight?document.body.clientHeight:document.body.scrollHeight;
}

return {"top":bodyST,"left":bodySL,"width":bodySW,"height":bodySH};
}

jQuery.fn.getBodySize=function(){
var bodyCW, bodyCH;
if(window.innerWidth)
bodyCW=window.innerWidth;
else if(document.documentElement&&document.documentElement.clientWidth)
bodyCW=document.documentElement.clientWidth;
else if(document.body)
bodyCW=document.body.clientWidth; //author: meizz

if(window.innerHeight)
bodyCH=window.innerHeight;
else if(document.documentElement&&document.documentElement.clientHeight)
bodyCH=document.documentElement.clientHeight;
else if(document.body)
bodyCH=document.body.clientHeight;

return {"width":bodyCW,"height":bodyCH};
}

function _alert(){
alert("OK");
}
</SCRIPT>
如何用DIV挡住SWF?

如何用DIV挡住SWF?

div在网页显示的时候,一般情况下都是被FLASH挡住,如何用div挡住flash呢?有一个小办法。。

由于现在flash在网页上显示大多用了swfObject的JS,因此,我也就拿它来举例:

<div id="flashContent">对不起,你的浏览器不支持flash</div>
<script>
var fso = new SWFObject("aaa.swf", "test", "100%", "100%", "8", "#FFFFFF");
//重点在这里
fso.addParam("wmode","opaque");
fso.write("flashContent");
</scirpt>
<div style="position:absolute;left:15;top:15;width:130px;height:30px;background:white"></div>

即,先给flash加上一个参数wmode,值为opaque,然后通过用DIV的绝对路径加上背景色来挡住flash,比如一个角,等等

JS全选checkBox最佳方案

JS全选checkBox最佳方案

<input type="button" name="" value="不计算长度" onclick="a()">
<input type="button" name="" value="全选" onclick="b()">
<input type="button" value="缓存" onclick="c()">
<input type="checkbox" name="test[]" value="0"> 测试测试<br>
<script language="JavaScript">
<!--
var ca = new Array();
function a()
{
var m = document.getElementsByName('test[]');
for ( var i=0; i< m.length ; i++ ){
m[i].checked = !m[i].checked;
}
}

function b(){
var m = document.getElementsByName('test[]');
var l = m.length;
for ( var i=0; i< l; i++){
m[i].checked = !m[i].checked;
}
}

function c(){
if (ca.length == 0){
ca = cache();
}
cl = ca.length;
for ( var i=0; i< cl; i++){
ca[i].checked = ! ca[i].checked;
}
}

function cache(){
var m = document.getElementsByName('test[]');
var cache = new Array();
var l = m.length;
for ( var i=0; i< l; i++){
cache[i] = m[i];
}
return cache;
}
//-->
</script>

  黑黑,至于那个input type="checkbox"的,你们就尽量复制吧,尽量不要超过1W,否则。。别怪我没有提醒你,当然了,也不需要把浏览器关掉,跑到外面抽根烟再回来就行了。

  所以,我们要切实的记住,反正数组有长度的,坚决不能放在循环里面,而是先将这个长度取出来当成变量。PHP里也一样,循环数组的时候,先count数组的长度比较好。
当然了,我第三个采用了缓存,速度也是非常快的,比长度取好后再进行计算更快,因为连一次都不用取了(当然,除了第一次),全部扔给客户端了。

  上面的例子还是比较方便的,因为,checkbox的 name值都一样,如果不一样怎么办???
  只能这样:

<script language="JavaScript">
<!--
function check(){
var inputs = document.getElementsByTagName('input');
var inputsLen = inputs.length;
for (var i = 0; i < inputsLen ; i++ ){
if (inputs[i].type.toLowerCase() == 'checkbox') {
inputs[i].checked = !inputs[i].checked;
}
}
}
//-->
</script>

JQuery学习第一天

JQuery,prototype,mootools是现在应用的比较多的JS框架了

其它的我就不谈了,现在正在用JQuery,正好做个笔记。

用JQuery官方的话来说,一般普通开发人员,如果仅仅是为了使用JQuery的话,那么,用的最多的应该是XPath,Css,只有这两个熟悉了,才能完整的使用JQuery,而XPath又是重中之重。

XPath的功能是让你可以在DOM里迅速定位到某一个确定的元素,在以前,我们不得不通过:getElementById,getElementsByName,等函数来得定位元素,而现在,$(),几乎可以完成常用的功能。

$('#test'),代表了以前的document.getElementById('test');

当然,这只是最简单的,复杂的就是在那些Xpath上了,例如
$("div > p") ,$("//div/p")等等
更详细的,可以参考:http://docs.jquery.com/DOM/Traversing/Selectors

用完了XPath后,就是一些常用的事件了,如click,mouseover,mouseout等这些都是可以后定义的也算是比较方便

对于页面元素,JQuery也简化了一些操作,比如取input框的值,取innerHTML,innerText等,不但取值方便,而且设定值的时候也非常方便。

今天的笔记就做到这样,只能算是稍稍理一下思路。慢慢再写