<!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>