ReferenceError:在函数JS

时间:2019-02-02 09:08:18

标签: javascript jquery

我有此代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>


var newPoint = "<div class='item-point' data-top='" + cY + "' data-left='" + cX + "' id='point" + random + "'>" +
"<div>" +
"<a onclick='test(1);' target='_blank' href='" + url + "'  class='toggle tooltips' title='" + description + "'  data-placement='top' data-html='true' rel='tooltip'><span class='pointFormat'>" + pointCount + "</span></a>" +
"</div>" +
"</div>";

$(".scalize").append(newPoint);


<div class="scalize"></div>

function test(variable) {
   alert(variable);
}

,它不起作用。我有错误:ReferenceError:找不到变量:variable。

点击链接(a href)时出现错误

如何修复?

1 个答案:

答案 0 :(得分:1)

您需要移动<style> #comment_box1 { background-color: #C8E0E8; width: 830px; height: 180px; } </style> 标签中所有的JavaScript和保持<script> HTML出来。像这样:

<div class="scalize"></div>