This time I will bring you jQueryHow to get the value of the tag sub-element, what are the precautions for jQuery to get the value of the tag sub-element, the following is a practical case, let's go together take a look.
1. Define the
<p> <span>科室:</span> <select class="dept-name-show" style="width: 70%;"> </select> </p>
2. Write js Statement:
<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>
3. Write the corresponding request statement:
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); } }
4. The effect is as follows:
I believe you have mastered the method after reading the case in this article. Please pay attention for more exciting things. Other related articles on php Chinese website!
Recommended reading:
How jQuery can create an animation effect that bounces when it hits the edge of the frame
jQuery's isPlainObject How to use the () method
Solution to the incompatibility of easyui in IE
How to implement the toggle method in jQuery
The above is the detailed content of How to get the value of tag sub-element with jQuery. For more information, please follow other related articles on the PHP Chinese website!