欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實(shí)現(xiàn)標(biāo)簽子元素的添加和賦值方法

 更新時(shí)間:2018年02月24日 09:57:47   作者:hacker_Lees  
下面小編就為大家分享一篇jQuery實(shí)現(xiàn)標(biāo)簽子元素的添加和賦值方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

一、在jsp頁面中定義<select>標(biāo)簽,如下:

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

二、編寫js語句:

<script>
$(function () {
var dname = $(".dept-name-show").eq(0);//選定<select>標(biāo)簽
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>

三、編寫對應(yīng)的請求語句:

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);
}
}

四、實(shí)現(xiàn)效果如下:

以上這篇jQuery實(shí)現(xiàn)標(biāo)簽子元素的添加和賦值方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論