|
在javascript中可以在一个function定义之后 立即调用该function: <script type="text/javascript"> var showMsg = function(){alert("自动运行的function")}(); </script> - <scripttype="text/javascript">
- varshowMsg=function(){alert("自动运行的function")}();
- </script>
给定义的function的花括号后面加上()即可。 软件开发网 www.mscto.com 还可以加上参数: <script type="text/javascript"> var showMsg = function(msg){alert(msg)}("带参数的 自运行的function"); </script> - <scripttype="text/javascript">
- varshowMsg=function(msg){alert(msg)}("带参数的自运行的function");
- </script>
|