Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
传递json数组onclick-html和javascript时出错_Javascript_Jquery_Html_Arrays_Json - Fatal编程技术网

传递json数组onclick-html和javascript时出错

传递json数组onclick-html和javascript时出错,javascript,jquery,html,arrays,json,Javascript,Jquery,Html,Arrays,Json,我正在使用jquery动态生成一个可点击列表。下面是生成列表的代码 for(dayint=0;dayint < day_arr.length;dayint++){ var temp_pass = JSON.stringify(day_arr[dayint]); //alert(temp_pass); $("#itin_list").append('<a href="#" style= "

我正在使用jquery动态生成一个可点击列表。下面是生成列表的代码

for(dayint=0;dayint < day_arr.length;dayint++){
                var temp_pass = JSON.stringify(day_arr[dayint]);
                //alert(temp_pass);
                $("#itin_list").append('<a  href="#" style= "border: 2px solid red;list-style-position: inside;min-height:500px; margin: 5px"  value="'+ temp_pass +'" class="list-group-item" onclick="sethiddendiv(this.value);"><b>Day  '+ dayint + ' of Trip from '+ start_n +' to '+ end_n +' </b> <button data-toggle="modal" data-target="#dirModal" style="position:absolute;bottom:5px; right:5px;float:right" class="btn btn-primary">Show Directions</button></a><br>');

            }
单击列表项时,它不会给出json数组,而是会一直提醒未定义

以下是我检查元素时在页面中生成的html:

<a href="#" style="border: 2px solid red;list-style-position: inside;min-height:500px; margin: 5px" value="[" 7.1896145,="" 79.7884585","7.9577778,="" 80.667518","8.3353156,="" 80.3329846"]"="" class="list-group-item" onclick="sethiddendiv(this.value);"><b>Day  0 of Trip from Colombo to  Kandy </b> <button data-toggle="modal" data-target="#dirModal" style="position:absolute;bottom:5px; right:5px;float:right" class="btn btn-primary">Show Directions</button></a> 
这里可能有什么问题?
我已经尝试过在onclick中使用单引号,但没有成功。欢迎任何帮助。我被卡住了。

首先,在值中有未替换的引号。您可能也不希望在值中使用等号。我通过只在值中传递一个整数id并执行单独的ajax查询来获得详细信息,从而解决了这个问题。在通过val传递json时,很难消除语法问题。
<a href="#" style="border: 2px solid red;list-style-position: inside;min-height:500px; margin: 5px" value="[" 7.1896145,="" 79.7884585","7.9577778,="" 80.667518","8.3353156,="" 80.3329846"]"="" class="list-group-item" onclick="sethiddendiv(this.value);"><b>Day  0 of Trip from Colombo to  Kandy </b> <button data-toggle="modal" data-target="#dirModal" style="position:absolute;bottom:5px; right:5px;float:right" class="btn btn-primary">Show Directions</button></a>