jQuery.isFunction()
jQuery.isFunction( obj ) 返回: boolean
描述: 确定的参数是一个Javascript 函数。
-
version added: 1.2jQuery.isFunction( obj )
obj用于测试是否为函数的对象
注意:jQuery 1.3以后,在IE浏览器里,浏览器提供的函数比如alert()
还有 DOM 元素的方法比如 getAttribute()
将不认为是函数。
Examples:
Example: Test a few parameter examples.
<!DOCTYPE html>
<html>
<head>
<style>
div { color:blue; margin:2px; font-size:14px; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div>jQuery.isFunction(objs[0]) = <span></span></div>
<div>jQuery.isFunction(objs[1]) = <span></span></div>
<div>jQuery.isFunction(objs[2]) = <span></span></div>
<div>jQuery.isFunction(objs[3]) = <span></span></div>
<div>jQuery.isFunction(objs[4]) = <span></span></div>
<script>
function stub() {
}
var objs = [
function () {},
{ x:15, y:20 },
null,
stub,
"function"
];
jQuery.each(objs, function (i) {
var isFunc = jQuery.isFunction(objs[i]);
$("span").eq(i).text(isFunc);
});
</script>
</body>
</html>
Demo:
Example: Finds out if the parameter is a funcion.
$.isFunction(function(){});
Result:
true