$.isFunction(sdopen) && sdopen()
工作正常
但是如何检查函数是否有像这样的参数
sdopen(uu)
最佳答案
您可以使用Function.length属性(property)
The length property specifies the number of arguments expected by the function.
$.isFunction(sdopen) && sdopen.length == 1 && sdopen(uu)
如 Praveen Kumar ,正确指出。检查是否为函数不需要使用jQuery,使用纯JavaScript即可实现。
typeof sdopen == "function"
function sdopen(a) {
alert(a)
}
$.isFunction(sdopen) && sdopen.length == 1 && sdopen('Yahooooooooooo');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
关于javascript - 如何检查函数是否有参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36793367/