jquery中的字符串拼接

前文:

 1 <div class="row text-center form-table">
 2                                 <%
 3                                     User user = (User) session.getAttribute("user");
 4                                     String school = user.getSchool();
 5                                     String[] info = school.split(":");
 6                                     request.setAttribute("info", info);
 7                                     for (int i = 0; i < info.length; i++) {
 8                                         String[] split = info[i].split("=");
 9                                         String schoolName = split[0];
10                                         String[] times = split[1].split("%");
11                                 %>
12                                 <div class="col-md-1">
13                                     <div class="rowhead">序号</div>
14                                     <div>
15                                         <input type="text" class="form-control input-sm text-center" value="<%=i+1%>">
16                                     </div>
17 
18                                 </div>
19                                 <div class="col-md-5 ">
20                                     <div class="rowhead"> 学校名称</div>
21                                     <div>
22                                         <input type="text" class="form-control input-sm" id="<%="school"+(i+1)%>"
23                                                value="<%=schoolName%>">
24                                     </div>
25                                 </div>
26                                 <div class="col-md-3 ">
27                                     <div class="rowhead">开始时间</div>
28                                     <div>
29                                         <input type="text" class="form-control input-sm" id="<%="startTime"+(i+1)%>"
30                                                value="<%=times[0]%>">
31                                     </div>
32                                 </div>
33                                 <div class="col-md-3">
34                                     <div class="rowhead">结束时间</div>
35                                     <div>
36                                         <input type="text" class="form-control input-sm" id="<%="endTime"+(i+1)%>"
37                                                value="<%=times[1]%>">
38                                     </div>
39                                 </div>
40                                 <%
41                                     }
42                                 %>
43                             </div>

在Jquery中获取值:

var length = <%=info.length%>;
                var school = "";
                for (var i = 1; i < length + 1; i++) {
                    var tmp1="school"+i;
                    var schoolTmp = $("#"+tmp1).val();
                    var tmp2 = startTime + i;
                    var startTime = $("input[id="+tmp2+"]").val();
                    var endTime = $("#"+"endTime"+i).val();
                    if (i == length) {
                        school = school + schoolTmp + "=" + startTime + "%" + endTime;
                    } else {
                        school = school + schoolTmp + "=" + startTime + "%" + endTime + ":";
                    }
                }

重点:

收获1:除 $("input[id=‘account‘]") 这种通过id获取值方式外,还有 $("#"+tmp1),得记住;

收获2:在 这里面使用自定义的变量时,加在变量两边加 + 号 --> $("input[id="+tmp2+"]")

收获3:

var tmp1="school"+i;
var schoolTmp = $("#"+tmp1).val();
var tmp2 = ‘startTime‘ + i;
var startTime = $("input[id="+tmp2+"]").val();
var endTime = $("#"+"endTime"+i).val();

jquery中的字符串拼接

上一篇:移动互联网的架构设计浅谈一


下一篇:2018-2019-2 20175105王鑫浩《Java程序设计》实验四 《Android开发基础》实验报告