欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Prototype 學(xué)習(xí) 工具函數(shù)學(xué)習(xí)($w,$F方法)

 更新時(shí)間:2009年07月12日 22:12:33   作者:  
Prototype $w $F使用方法
$w方法
Splits a string into an Array, treating all whitespace as delimiters. Equivalent to Ruby's %w{foo bar} or Perl's qw(foo bar).
復(fù)制代碼 代碼如下:

function $w(string) {
if (!Object.isString(string)) return [];
string = string.strip();
return string ? string.split(/\s+/) : [];
}

這個(gè)方法就是用空白字符把字符串分成數(shù)組,然后返回。
例子:
復(fù)制代碼 代碼如下:

$w('apples bananas kiwis') // -> ['apples', 'bananas', 'kiwis']

$F方法
Returns the value of a form control. This is a convenience alias of Form.Element.getValue.
復(fù)制代碼 代碼如下:

var $F = Form.Element.Methods.getValue;
//====>getValue()
getValue: function(element) {
element = $(element);
var method = element.tagName.toLowerCase();
return Form.Element.Serializers[method](element);
}
//====>Serializers
Form.Element.Serializers = {
input: function(element, value) {
switch (element.type.toLowerCase()) {
case 'checkbox':
case 'radio':
return Form.Element.Serializers.inputSelector(element, value);
default:
return Form.Element.Serializers.textarea(element, value);
}
},
inputSelector: function(element, value) {
if (Object.isUndefined(value)) return element.checked ? element.value :
null;
else element.checked = !!value;
},
textarea: function(element, value) {
if (Object.isUndefined(value)) return element.value;
else element.value = value;
},
//省略,以后說到這個(gè)對(duì)象的時(shí)候在詳細(xì)說明
......
//====> Object.isUndefined
function isUndefined(object) {
return typeof object === "undefined";
}

這個(gè)函數(shù)最后就是返回傳入?yún)?shù)的值。從Form.Element.Serializers 這個(gè)對(duì)象里面定義的方法可以看出,$F方法取得的是Form元素的值,如果定義一個(gè)div然后調(diào)用這個(gè)方法將會(huì)拋出Form.Element.Serializers[method] is not a function異常,如果給定的ID不存在將會(huì)拋出element has no properties異常。
在Form.Element.Serializers 里面的方法中先檢查value這個(gè)參數(shù)是否存在,存在就相當(dāng)于給element參數(shù)賦值,不存在就會(huì)返回element的值

相關(guān)文章

最新評(píng)論