【发布时间】:2011-11-25 15:11:32
【问题描述】:
我在页面上有一些脚本试图弄清楚它在做什么:
(function ($, window, undefined)
{
var
// String constants for data names
dataFlag = "watermark",
dataClass = "watermarkClass",
dataFocus = "watermarkFocus",
dataFormSubmit = "watermarkSubmit",
dataMaxLen = "watermarkMaxLength",
dataPassword = "watermarkPassword",
dataText = "watermarkText",
// Copy of native jQuery regex use to strip return characters from element value
rreturn = /\r/g,
// Includes only elements with watermark defined
selWatermarkDefined = "input:data(" + dataFlag + "),textarea:data(" + dataFlag + ")",
// Includes only elements capable of having watermark
selWatermarkAble = "input:text,input:password,input[type=search],input:not([type]),textarea",
// triggerFns:
// Array of function names to look for in the global namespace.
// Any such functions found will be hijacked to trigger a call to
// hideAll() any time they are called. The default value is the
// ASP.NET function that validates the controls on the page
// prior to a postback.
//
// Am I missing other important trigger function(s) to look for?
// Please leave me feedback:
// http://code.google.com/p/jquery-watermark/issues/list
triggerFns = [
"Page_ClientValidate"
],
// Holds a value of true if a watermark was displayed since the last
// hideAll() was executed. Avoids repeatedly calling hideAll().
pageDirty = false,
// Detects if the browser can handle native placeholders
hasNativePlaceholder = ("placeholder" in document.createElement("input"));
/*******************************************************/
/* Enable / disable other control on trigger condition */
/*******************************************************/
$.fn.TriggerContol = function (options)
{
我在最后两行苦苦挣扎。开发者为什么要用fn,这是什么意思?
我知道整个文件基本上是一个自调用匿名函数,旨在将函数附加到 Jquery 库,以便您可以执行 jQuery(x).TriggerControl。我只是想知道这个特殊的结构是什么意思。
【问题讨论】:
标签: javascript jquery