更新時間:2021-06-25 11:47:17 來源:動力節(jié)點 瀏覽2276次
在頁面中引入javascript文件的方式是多種多樣的,本文介紹一種。
1.在eclipse中新建一個web項目(project3),目錄結(jié)構(gòu)如下:

2.在jsp頁面的最開始,獲取項目的根路徑。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
則:
path=project3
basePath=http://localhost:8080/project3/
3.在<head></head>中,插入下述代碼:
<base href="<%=basePath%>"> //這句代碼的作用是將整個頁面的根路徑設(shè)置為項目路徑。
4.引入js文件
<script src="js/laydate.js"></script> //http://localhost:8080/project3/js/laydate.js
5.測試
<script>
laydate.render({
elem: '#test1' //指定元素
});
</script>
<body>
<input type="text" name="date" placeholder="請選擇日期" id="test1" value="">
</body>
6.結(jié)果

大家如果想學(xué)習(xí)更多的Java技術(shù),可以到動力節(jié)點官網(wǎng)上的Java視頻教程頁面去下載免費的教程,當(dāng)然也有相關(guān)的配套技術(shù)文檔可以學(xué)習(xí)。