jQuery.isFunction()方法

jQuery 雜項方法jQuery 雜項方法

實例

測試一些參數是否為函數

<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 雜項方法jQuery 雜項方法