![](/img/trans.png)
[英]Detect change of value of struts2 autocompleter tag using javascript or jquery
[英]Getting Uncaught TypeError errors using Struts2 JQuery datepicker tag
我有一個帶有使用引導程序構建的 UI 的 Struts 2 應用程序,並且正在嘗試使用 struts2 jquery 標記庫使 JQuery 日期選擇器工作。 我正在使用<sj:head compressed="true" jqueryui="true" />
來包含 JQuery CSS 和 JS 庫。 以下是使用sj:head
包含的內容:
<script type="text/javascript" src="/struts/js/base/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/struts/js/base/jquery.ui.core.min.js?s2j=3.7.1"></script>
<script type="text/javascript" src="/struts/js/plugins/jquery.subscribe.min.js?s2j=3.7.1"></script>
<script type="text/javascript" src="/struts/js/struts2/jquery.struts2.min.js?s2j=3.7.1"></script>
<script type="text/javascript">
$(function () {
jQuery.struts2_jquery.version = "3.7.1";
jQuery.scriptPath = "/struts/";
jQuery.ajaxSettings.traditional = true;
jQuery.ajaxSetup({
cache: false
});
jQuery.struts2_jquery.require("js/struts2/jquery.ui.struts2.min.js?s2j=3.7.1");
});
</script>
<link id="jquery_theme_link" rel="stylesheet"
href="/struts/themes/smoothness/jquery-ui.css?s2j=3.7.1" type="text/css"/>
下面是 JSP 中與 datepicker 相關的代碼:
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<div class="form-group row">
<label class="col-sm-2 control-label">From</label>
<div class="col-sm-4">
<sj:datepicker id="fromDate" displayFormat="m/d/y" showOn="focus" name="startDate"></sj:datepicker>
</div>
<label class="col-sm-2 control-label">To</label>
<div class="col-sm-4">
<sj:datepicker id="toDate" displayFormat="m/d/y" showOn="focus" name="endDate"></sj:datepicker>
</div>
</div>
<script>
$(function() {
$("#fromDate").datepicker({
dateFormat: 'yy-mm-dd',
maxDate: 0,
changeYear: true
}).attr('readonly', 'readonly');
$("#toDate").datepicker({
dateFormat: 'yy-mm-dd',
maxDate: 0,
changeYear: true
}).attr('readonly', 'readonly');
});
</script>
這些字段顯示得很好,似乎也工作正常。 但是,我在控制台中收到以下錯誤:
Uncaught TypeError: Cannot set properties of undefined (setting 'version')
at HTMLDocument.<anonymous> (viewResults:62:39)
at j (jquery-1.11.0.min.js:776:111)
at Object.fireWith [as resolveWith] (jquery-1.11.0.min.js:810:100)
at Function.ready (jquery-1.11.0.min.js:865:65)
at HTMLDocument.K (jquery-1.11.0.min.js:873:97)
jquery-3.1.1.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'initDatepicker')
at HTMLDocument.<anonymous> (viewResults:360:27)
at j (jquery-3.1.1.min.js:2:29948)
at k (jquery-3.1.1.min.js:2:30262)
jquery-3.1.1.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'bind')
at HTMLDocument.<anonymous> (viewResults:372:26)
at j (jquery-3.1.1.min.js:2:29948)
at k (jquery-3.1.1.min.js:2:30262)
jquery-3.1.1.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'initDatepicker')
at HTMLDocument.<anonymous> (viewResults:382:27)
at j (jquery-3.1.1.min.js:2:29948)
at k (jquery-3.1.1.min.js:2:30262)
jquery-3.1.1.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'bind')
at HTMLDocument.<anonymous> (viewResults:394:26)
at j (jquery-3.1.1.min.js:2:29948)
at k (jquery-3.1.1.min.js:2:30262)
我無法弄清楚導致這些錯誤的原因是什么。 我嘗試刪除sj:head
並手動包含庫,但這也不起作用。
加載了錯誤版本的 jQuery 框架。
<script type="text/javascript" src="/struts/js/base/jquery-1.11.0.min.js"></script>
不要在同一頁面上兩次加載 jQuery 庫。 第一次加載它
<script src="... ">
第二次加載它
<sj:head/>
您應該在<head>
標記的正文中包含<sj:head/>
標記。
如果您使用<sj:head>
標簽,那么您可以自定義它以使用不同版本的 jQuery。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.