我在脚本标记中有一个函数,它在一个名为" filters.js"的单独文件中初始化几个脚本。但由于某种原因,它返回"初始化未定义"。在jQuery中包装函数会改变范围吗?这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<script src="Scripts/filters.js"></script>
<script src="Scripts/jquery-3.3.1.js"></script>
<meta charset="utf-8" />
<title>ICTV Filters</title>
</head>
<body>
<div class="filterCategory">
<div class="categoryTitle">
Genome
<input type="checkbox" id="ssDNA" />
<label for="ssDNA">ssDNA</label>
<input type="checkbox" id="dsDNA" />
<label for="dsDNA">dsDNA</label>
<input type="checkbox" id="ssRNA" />
<label for="ssRNA">ssRNA</label>
<input type="checkbox" id="dsRNA" />
<label for="dsRNA">dsRNA</label>
<button onclick="initialize()">Apply Filters</button> <!-- Returns error on this line-->
</div>
</div>
<div class="filterReturn">
<p id="filterReplace"></p>
</div>
<script>
jQuery(document).ready(function () {
function initialize() {
getSelections();
updateObject();
updateLocalStorage();
$(document).trigger('filtersUpdated');
}
})
</script>
</body>
</html>