EL表達式的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>    

形如上面的代碼,因為${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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM