jQuery.isFunction()方法
jQuery 教程
· 2019-03-28 21:38:35
实例
测试一些参数是否为函数
<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 () {
function stub() {}
var objs = [
function() {},
{ x:15, y:20 },
null,
stub,
"function"
];
$.each( objs, function( i ) {
var isFunc = $.isFunction( objs[ i ]);
$( "span" ).eq( i ).text( isFunc );
});
})
</script>
定义和用法
$.isFunction()函数用于判断指定参数是否是一个函数。
注意:jQuery 1.3之后的版本,例如在 Internet Explorer 中,由浏览器提供的函数alert(),以及 DOM 元素方法(比如 getAttribute())将不被认为是函数。
语法
$.isFunction( object )
| 参数 | 描述 |
|---|---|
| object | 任意类型 需要进行判断的任意值。 |
点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html
Ajax Design Patterns
Michael Mahemoff / O'Reilly Media / 2006-06-29 / USD 44.99
Ajax, or Asynchronous JavaScript and XML, exploded onto the scene in the spring of 2005 and remains the hottest story among web developers. With its rich combination of technologies, Ajax provides a s......一起来看看 《Ajax Design Patterns》 这本书的介绍吧!