所以我有以下代码,从 JQuery 上下文调用时 glassLoad() 不起作用。我已将问题隔离到一个特定的行,myBox.apos('170px', '150px');
这似乎阻止了整个函数的运行,但仅在从 JQuery 调用时。如果我使用标准onclick="glassLoad();"
,它会完美地运行该函数,但如果我在 JQuery 中包含该函数,它将停止整个 JQuery 函数的运行:
@model IEnumerable<OneEightyWebApp.Models.PropertyDB>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" media="screen" />
<script src="../../Content/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
<head>
<title></title>
<script type="text/javascript">
function populate() {
var select = document.getElementById("centres");
for (var i = 1; i <= 10; i++) {
var option = document.createElement("option");
option.value = i;
option.text = i;
select.appendChild(option);
}
}
function divGenerator() {
var div;
for (var i = 1; i <= document.getElementById("revisions").value; i++) {
div = document.createElement("div");
div.className = "class1";
div.innerHTML = "Space " + i;
div.style.width = "100px";
div.style.height = "100px";
div.style.float = "left";
document.getElementById("container2").appendChild(div);
}
}
function glassLoad() {
path_to_root_dir = "../../Content/";
var myBox = new GlassBox();
myBox.init('myBox', '128px', '62px', 'hidden');
myBox.apos('170px', '150px');
}
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
<script type="text/javascript">
$(document).ready(function () {
$("body").on("click", ".class1", function () {
glassLoad();
alert("div clicked");
});
});
</script>
</head>
<body>
<!--
<a href="javascript:myFunc();">popup</a>
-->
<div id="container1" style="width: auto; height: 50px;">
<button style="margin: auto; vertical-align: top; float: left; font-size: 16px;" type="button" onclick="divGenerator();">Generate</button>
@Html.DropDownList("revisions", (List<SelectListItem>)ViewData["revisions"])
</div>
<div id="container2" style="margin: 10px; float: left;"></div>
<div id="myBox">Hello!</div>
</body>