Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将多个字符串参数传递给Jquery函数_Javascript_Jquery_Html - Fatal编程技术网

Javascript 将多个字符串参数传递给Jquery函数

Javascript 将多个字符串参数传递给Jquery函数,javascript,jquery,html,Javascript,Jquery,Html,我试图将一些字符串参数传递给页面中的jQuery函数。我的jQuery看起来像这样 function showModal(text1, text2, text3) { $('#modal1').text(text1); $('#modal2').text(text2); $('#modal3').text(text3); $('#modal').modal('toggle'); } <spring:messag

我试图将一些字符串参数传递给页面中的jQuery函数。我的jQuery看起来像这样

   function showModal(text1, text2, text3) {
        $('#modal1').text(text1);
        $('#modal2').text(text2);
        $('#modal3').text(text3);
        $('#modal').modal('toggle');
    }
<spring:message javaScriptEscape="true" var="text1"
                            text="${obj1.text}"/>
            <spring:message javaScriptEscape="true" var="text2"
                            text="${obj1.text2}"/>
            <spring:message javaScriptEscape="true" var="text3"
                            text="${obj1.text3}"/>    

<tr onclick="showModal('${text1}, ${text2}, ${text3}');"> 
调用函数的那一行看起来像这样

   function showModal(text1, text2, text3) {
        $('#modal1').text(text1);
        $('#modal2').text(text2);
        $('#modal3').text(text3);
        $('#modal').modal('toggle');
    }
<spring:message javaScriptEscape="true" var="text1"
                            text="${obj1.text}"/>
            <spring:message javaScriptEscape="true" var="text2"
                            text="${obj1.text2}"/>
            <spring:message javaScriptEscape="true" var="text3"
                            text="${obj1.text3}"/>    

<tr onclick="showModal('${text1}, ${text2}, ${text3}');"> 

此行中的单引号:

<tr onclick="showModal('${text1}, ${text2}, ${text3}');">

正在分隔字符串,因此您只向函数传递一个参数。尝试:

<tr onclick="showModal('${text1}', '${text2}', '${text3}');"> 


有效!谢谢您!如果这个答案解决了您的问题@BrijParel,请务必接受。