我有一个问题,我正在尝试通过 javascript 动态添加一些 html,并且 html 有一个 js 函数,它应该在单击它时触发,但无论我做什么我都会收到这个错误Uncaught SyntaxError: Unexpected token }
以前有人遇到过这个问题吗?
$("#addVehicle").click(function () {
vehicleQueue += '<li class="ui-state-default">' + $("#years option:selected").text() + ' - ' + $("#make option:selected").text() + ' - ' + $("#model option:selected").text() + ' - ' + $("#trim option:selected").text() + '<span><img onclick="javascript:alert("Hola");" class="removeVehicle" width="25px" src="http://haveagreatholiday.com/img/popup-closeButton.png"></span></li>';
$("#vehicleQueue").html('<ul id="sortable">' + vehicleQueue + '</ul>');
vehicleJson.push({
vehicleCount: vehicleCount,
vehicleYear: $("#years option:selected").text(),
vehicleMake: $("#make option:selected").text(),
vehicleModel: $("#model option:selected").text(),
vehicleTrim: $("#trim option:selected").text()
});
vehicleCount++;
});
这是我的头:
<head>
<script type="text/javascript" src="view.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="functions.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 97%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.2em; height: 18px; }
#sortable li span {width: 16px;height: 17px;display: block;text-decoration: none;position: absolute;right: 18px;top: 3px;}
</style>
</head>