我想这样在jQuery中编写此函数
function hello(a = ''){
if(a != '') alert("hello");
}
我的jQuery代码是这样的
var hello = function(a = ''){
if(a != '') alert("hello");
}
以下功能在台式机浏览器和android chrome浏览器中工作正常,但在androd本机浏览器中不起作用,并给我以下错误。
E/browser (26360): Console: Uncaught SyntaxError: Unexpected token =:122
只需输入参数,如果没有传递任何参数,它将返回undefined:
var hello = function( myVal ){
// or you can set it defaut value by using
// if ( !myVal ) myVal = 'bla bla';
if(myVal) alert("hello");
}
您使用的是default function paramater
EcmaScript 2015的新功能,称为。并不是所有平台都支持它。您可以检查此链接的兼容性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句