所属分类:Windows编程 开发工具:Others 文件大小:35KB 下载次数:4 上传日期:2013-01-22 21:07:39 上 传 者:no name
说明: 填充表单字段与示例文本,消失在焦点。
支持一个选项:
类名:集的类名示例文本中使用的样式表(默认情况下它是例子)。
这个插件是完全兼容插件的元数据,允许您设置示例文本通过示例属性和标准的类名属性元素本身。
(Supports one option:
className: Sets the class name of the example text for use in a stylesheet (by default it is example).
This plugin is fully compatible with the Metadata plugin, allowing you to set the example text via the example property and the standard className property in elements themselves.)
jQuery Form Example Plugin 1.4.1
======================================
This is a jQuery plugin to populate form inputs with example text that
disappears on focus.
Basic usage revolves around the use of the `example` function like so:
$('input#name').example('Bob Smith');
This will then put the example text "Bob Smith" into the input with the ID
"name". When a user then focuses on this input, the example text will
disappear, allowing them to enter their data. If they then click elsewhere
*without entering any information*, the example will re-appear.
By default, example text is given the class `example`, allowing you to style
it with CSS like so:
.example { color: #666; }
If this class name conflicts with one you already use, you can override it
with the `className` option like so:
$('input#name').example('Bob Smith', { className: 'hint' });
The above example would then be given the class `hint` instead of `example`.
If you plan to use the same options repeatedly, it is possible to override the
plugin's defaults directly:
$.fn.example.defaults.className = 'notExample';
This will cause any uses of the plugin after this point to use the new
defaults.
As well as supplying the example text via a string, a callback function can be
used instead to determine the value at runtime:
$('input#name').example(function() {
return $(this).attr('title');
});
The above example will set the example text to the `title` attribute of the
input. The callback is executed within the context of the input field so, as
in the example above, `$(this)` will return the input itself.
It is worth noting that the callback is evaluated every time the example text
needs to be inserted and *is not cached*. This makes it possible to
dynamically change the example text of a field after page load like so:
$('input#name').example(function() {
var text = $(this).attr('title');
$(this).attr('title', 'Not the original title anymore');
return text;
});
The plugin also supports the jQuery Metadata plugin which allows you to
specify metadata in elements themselves. You can specify the example text and
hide_label options like so:
Please note that metadata will be overridden by arguments, e.g.
$('#m1').example('Another example');
The example will be set to "Another example" instead of "An example".
Testing
-------
As of 1.4, this plugin now comes with a QUnit test suite that you can find
in the test/ directory and run by opening index.html in your browser.
Compatibility
-------------
This plugin has been tested with jQuery 1.1 and newer and should work in all
browsers supported by jQuery itself (it has been tested with Safari 4, Google Chrome 0.2.149.29, Mozilla Firefox 3, Opera 9.52 and
Internet Explorer 7).
Author
------
This plugin was written by and is maintained by Paul Mucur aka "mudge". Please
do not hesitate to contact me with comments and bug reports through the
plugin's official entry on the jQuery Plugins directory:
http://plugins.jquery.com/project/example
You can view the latest source code (and fork the entire project if you wish)
at http://github.com/mudge/jquery_example
Contributors
------------
The code to support the Metadata plugin was contributed by DeLynn Berry (http://github.com/delynn).
Licensing
---------
Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
Licenses.
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.