国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現標簽子元素的添加和賦值方法

2019-11-19 14:19:00
字體:
來源:轉載
供稿:網友

一、在jsp頁面中定義<select>標簽,如下:

<div><span>科室:</span><select class="dept-name-show" style="width: 70%;"></select></div>

二、編寫js語句:

<script>$(function () {var dname = $(".dept-name-show").eq(0);//選定<select>標簽var url = "${pageContext.request.contextPath}/getDepts.do";//請求路徑$(".dept-name-show").click(function () {$.get(url,function (res) {var len = res.length;var op = dname.children().length;if (op < len) {var pp = "<option></option>";for (var i = 0; i < len; i++) {dname.append(pp);dname.children().eq(i).text(res[i].name);}}})})})</script>

三、編寫對應的請求語句:

List<Dept> deptList=null;@RequestMapping(value = "/getDepts",method = {RequestMethod.GET})public void getDepts(HttpServletResponse response) throws IOException {response.setCharacterEncoding("utf-8");response.setContentType("text/json;charset=utf-8");if (deptList == null){deptList = deptService.findAllDepts();}else {String res=JSON.toJSONString(deptList);response.getWriter().write(res);}}

四、實現效果如下:

以上這篇jQuery實現標簽子元素的添加和賦值方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和平区| 建宁县| 盐津县| 两当县| 蓝山县| 安阳市| 阳信县| 九龙城区| 监利县| 大埔区| 洪湖市| 平湖市| 库伦旗| 鞍山市| 偃师市| 屏边| 巴东县| 渭南市| 鹰潭市| 秦安县| 衡东县| 夏津县| 志丹县| 阿合奇县| 黎川县| 广安市| 霍州市| 庆元县| 博罗县| 布拖县| 鄂州市| 灵丘县| 蒲城县| 当涂县| 忻城县| 榆树市| 双牌县| 沅江市| 开平市| 鲁甸县| 扶沟县|