JQUERY附加一个带有onClick事件的按钮并在其中传递javascript变量 parameters=eval([\'April\',[\'medical\',\'1\',[\'financial\',\'4\',[\'thrimble\',\'1\']],[\'May\',[\'medical\',\'2\',[\'financial\',[\'6\'],[\'thrimble\','6\']); 参数“#容器”、“图表”、“饼图”)”/>; $(“#内容”).append(myButton);
我的问题是,每当我点击按钮时,它都不会执行该功能。可能是因为我传递的变量参数,我的问题是如何才能正确地做到这一点?我避免使用ajax,因为它会影响我大部分的代码。试试这个:使用转义字符,并使用加号操作符添加参数变量JQUERY附加一个带有onClick事件的按钮并在其中传递javascript变量 parameters=eval([\'April\',[\'medical\',\'1\',[\'financial\',\'4\',[\'thrimble\',\'1\']],[\'May\',[\'medical\',\'2\',[\'financial\',[\'6\'],[\'thrimble\','6\']); 参数“#容器”、“图表”、“饼图”)”/>; $(“#内容”).append(myButton);,javascript,php,jquery,append,json,Javascript,Php,Jquery,Append,Json,我的问题是,每当我点击按钮时,它都不会执行该功能。可能是因为我传递的变量参数,我的问题是如何才能正确地做到这一点?我避免使用ajax,因为它会影响我大部分的代码。试试这个:使用转义字符,并使用加号操作符添加参数变量 <script> parameter=eval("[[\"April\",[[\"medical\",\"1\"],[\"financial\",\"4\"],[\"burial\",\"1\"]]],[\"May\",[[\"medical\",\"2\"],[
<script>
parameter=eval("[[\"April\",[[\"medical\",\"1\"],[\"financial\",\"4\"],[\"burial\",\"1\"]]],[\"May\",[[\"medical\",\"2\"],[\"financial\",\"6\"],[\"burial\",\"6\"]]]]");
myButton="<input type="submit" value="Pie Chart" onClick="showChart('<?php echo $title;?>',parameters,'#container','chart','Pie Chart')"/>";
$('#content').append(myButton);
</script>
参数=eval(“[\'April\”、[[\'medical\”、[\'1\”]、[\'financial\”、\'4\”]、[\'Hearting\”、\'1\“]]、[\'May\”、[\'medical\”、[\'2\”]、[\'financial\”、[\'6\”]、[\'Hearting\”、\'6\']]”;
我的按钮=”
首先,您可以看到jQuery的.on函数来获取单击执行函数时的事件处理程序。您可以将其作为JavaScript附加到div的html中,这样就不必使用按钮本身的onclick
第二,要扩展innerhtml或类似元素的html,必须使用.html(data)。或者,我在我的帖子上面看到:可以使用append
问候语从不使用-eval-我使用eval将返回的json编码转换为javascript对象。它以hmtl方式工作,因此在脚本中我不应该使用它?是的,您不应该使用json.parse
<script>
parameter=eval("[[\"April\",[[\"medical\",\"1\"],[\"financial\",\"4\"],[\"burial\",\"1\"]]],[\"May\",[[\"medical\",\"2\"],[\"financial\",\"6\"],[\"burial\",\"6\"]]]]");
myButton="<input type="submit" value="Pie Chart" onClick="showChart('<?php echo $title;?>',parameters,'#container','chart','Pie Chart')"/>";
$('#content').append(myButton);
</script>
<script>
parameter=eval("[[\"April\",[[\"medical\",\"1\"],[\"financial\",\"4\"],[\"burial\",\"1\"]]],[\"May\",[[\"medical\",\"2\"],[\"financial\",\"6\"],[\"burial\",\"6\"]]]]");
myButton="<input type=\"submit\" value=\"Pie Chart\" onClick=\"showChart('<?php echo $title;?>',"+parameters+",'#container','chart','Pie Chart')\"/>";
$('#content').append(myButton);
</script>
jQuery('#yourbutton').on('click', function() {
}); // your on click event
//to add content to innerhtml of div:
jQuery('#divelementorother').html(jQuery('#divelementorother').html() + YourDataToInside);