js中function的三种写法
以下是js中function的三种写法:
第⼀种是最普通的写法, 即声明⼀个函数。并在接受组件onclic事件是触发函数。
第⼆种写法是函数直接两的写法,即将函数赋给⼀个变量,然后调⽤这个变量,即可执⾏该函数。
最后⼀种写法就是利⽤构造函数来执⾏。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>⽆标题⽂档</title>
</head>
<body>
<mce:script language="javascript" ><!--
function frameOut(msg){
alert(msg);
} //第⼀种⽅法,普通的函数写法
js方法function frameOut2(msg){
var x = function (argument){
alert(argument);
};
return x(msg); //函数直接量
}
function frameOut3(msg){
x = new Function("msg","alert(msg)");
x(msg); //利⽤构造函数
}
// --></mce:script>
<input type="button" value="点击我,弹出框的" οnclick="frameOut('Hello World')"/>
<input type="button" value="第⼆种⽅法点击" οnclick="frameOut2('Hello World')" />
<input type="button" id="third" value="第三种⽅法点击" οnclick="frameOut3('Hello World')" />
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论