- <!Doctype html>
- <html>
- <head>
- <title>
- js的传参问题
- </title>
- <script type="text/javascript">
- function get(username) {
- alert(username);
- }
- </script>
- </head>
- <body>
- <input type="button" value="点我" onclick="get(${user.username })" />
- </body>
- </html>
形如上面的代码,因为 ${user.username} 得到的是字符串类型,假设得到的值为 zhangSan。这样 get(${user.username}) 就相当于 get(zhangSan), 但是这样写的 js 函数根本就不会执行。要写成下面的形式,js 函数才会执行。当时因为这个问题,困扰我半天。。。。。。
- <!Doctype html>
- <html>
- <head>
- <title>
- js的传参问题
- </title>
- <script type="text/javascript">
- function get(username) {
- alert(username);
- }
- </script>
- </head>
- <body>
- <input type="button" value="点我" onclick="get('${user.username}')" />
- </body>
- </html>
来源: