最高半折刷qq各种业务和钻(家里人自己开的,尽管放心,大家多捧捧场)

sking7

导航

HTMLFormElement--length属性

<html>
<style type="text/css">
.contentTable
{ background-color: #9E9E9E; font-size: 12px}
.defaultBGColor
{BACKGROUND-COLOR: #FFFFFF}
</style>

<body>
<input type="button" value="c" onclick=""/>
<div id="test"></div>
</body>
<form id="f">
<input type="text"/>
<input type="text" id="t" />
</form>
<script>
alert(document.getElementById(
'f').length);//2
alert(document.getElementById(
't').length);//undefined
</script>
</html>

HTMLFormElement有长度属性。。这也就是下面在YUI框架里要验证length的原因、、因为Element也有可能有length但不是  like  Array的集合

/**
Evaluates _obj_ to determine if it's an array, an array-like collection, or
something else. This is useful when working with the function `arguments`
collection and `HTMLElement` collections.

Note: This implementation doesn't consider elements that are also
collections, such as `<form>` and `<select>`, to be array-like.

@method test
@param {Object} obj Object to test.
@return {Number} A number indicating the results of the test:

* 0: Neither an array nor an array-like collection.
* 1: Real array.
* 2: Array-like collection.

@static
**/

YArray.test = function (obj) {
var result = 0;

if (Lang.isArray(obj)) {
result = 1;
} else if (Lang.isObject(obj)) {
try {
// indexed, but no tagName (element) or alert (window),
// or functions without apply/call (Safari
// HTMLElementCollection bug).
if ('length' in obj && !obj.tagName && !obj.alert && !obj.apply) {
result = 2;
}
} catch (ex) {}
}

return result;
};



posted on 2012-02-29 18:29  G.N&K  阅读(354)  评论(0编辑  收藏  举报