JQuery,ajax異步加載selectoption/option/select多選框:

摘要:最近項目中用到了jquery,ajax,由于很長時間沒用了,所以這次做花了很多時間,現在記錄一下,方便以后回憶:

一:js文件:

<script type="text/javascript">// 進出港顯示字段權限分配function jingchugang(){var tableName = $('input:radio:checked').val();$.ajax({type:"POST",url:"<s:url value='/u/showFieldSet'/>",data:"tableName="+tableName,dataType:"json",success:function(dataMap){var fieldList = dataMap.fieldList;if(fieldList != null && fieldList.length > 0){//var start = "<select id='selectL' name='selectL' multiple='multiple'>";//var str = '';for(var i = 0; i< fieldList.length; i++){//str += "<tr><td><input type='checkbox' id='fieldName' name='fieldName'/>"+fieldList[i].fieldName+"<td></tr>";//str += "<option value='"+fieldList[i].id+"'>"+fieldList[i].fieldName+"</option>";$("<option value='"+fieldList[i].id+"'>"+fieldList[i].fieldName+"</option>").appendTo("#selectL");}//var end = "</select>";//$("str").appendTo("#selectL");}},});} 
</script>

二:jsp文件:

<tr class="even"><td><div class="select_side"><p>待選區</p><select id="selectL" name="selectL" multiple="multiple"></select></div><div class="select_opt"><p id="toright" title="添加">></p><p id="toleft" title="移除"><</p></div><div class="select_side"><p>已選區</p><select id="selectR" name="selectR" multiple="multiple"></select></div><div class="sub_btn"><input type="button" id="sub" value="getValue" /></div></td></tr>

三:最后我把這個頁面附上:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ include file="../../common/include_tag.jsp"%>
<%@ include file="../../common/page_var.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=pageTitle%></title>
<link href="<s:url value='/images/favicon.ico'/>" rel="shortcut icon"type="image/x-icon" />
<%@ include file="../../common/page_head.jsp"%>
<script type="text/javascript">$(function() {pilicat.title2div('title2div');pilicat.keysubmit('form1', 'submit', true);});
</script>
<script type="text/javascript">
$(function(){var leftSel = $("#selectL");var rightSel = $("#selectR");$("#toright").bind("click",function(){		leftSel.find("option:selected").each(function(){$(this).remove().appendTo(rightSel);});});$("#toleft").bind("click",function(){		rightSel.find("option:selected").each(function(){$(this).remove().appendTo(leftSel);});});leftSel.dblclick(function(){$(this).find("option:selected").each(function(){$(this).remove().appendTo(rightSel);});});rightSel.dblclick(function(){$(this).find("option:selected").each(function(){$(this).remove().appendTo(leftSel);});});$("#sub").click(function(){var showFields = [];rightSel.find("option").each(function(){showFields.push(this.value);});showFields = showFields.join(",");if(showFields == ""){alert("沒有選擇任何項!");}else{alert(showFields);}});});
</script>
<script type="text/javascript">// 進出港顯示字段權限分配function jingchugang(){var tableName = $('input:radio:checked').val();$.ajax({type:"POST",url:"<s:url value='/u/showFieldSet'/>",data:"tableName="+tableName,dataType:"json",success:function(dataMap){var fieldList = dataMap.fieldList;if(fieldList != null && fieldList.length > 0){//var start = "<select id='selectL' name='selectL' multiple='multiple'>";//var str = '';for(var i = 0; i< fieldList.length; i++){//str += "<tr><td><input type='checkbox' id='fieldName' name='fieldName'/>"+fieldList[i].fieldName+"<td></tr>";//str += "<option value='"+fieldList[i].id+"'>"+fieldList[i].fieldName+"</option>";$("<option value='"+fieldList[i].id+"'>"+fieldList[i].fieldName+"</option>").appendTo("#selectL");}//var end = "</select>";//$("str").appendTo("#selectL");}},});} 
</script>
<script type="text/javascript">$(document).ready(function() {$('#form1').ajaxForm({dataType : 'json',beforeSubmit : checkForm,success : afterPost});});function checkForm(formData, jqForm, options) {alert(formData);}function afterPost(responseText, statusText, xhr, $form) {if (responseText.resultStatus == true) {parent.$.jBox.tip("保存成功,請刷新查看結果", "success", {timeout : 2000});parent.$.jBox.close(true);} else {$.jBox.error("保存失敗", "失敗信息");}}function submitForm() {getSelectAll();}
</script>
<style type="text/css">
.update {margin: 0 auto;padding: 0;width: 98%;
}.update td {margin: 0;height: 30px;padding: 5px;
}.update .name {text-align: right;
}.title_div {width: 350px;
}body {background: url("<s:url value='/images/gray_bg.png'/>") 0 0 repeat-y#F6F6F6;
}
</style>
<style type="text/css">
.select_side {float: left;width: 200px
}select {width: 180px;height: 120px
}.select_opt {float: left;width: 40px;height: 100%;margin-top: 36px
}.select_opt p {width: 26px;height: 26px;margin-top: 6px;background: url("<s:url value='/images/arr.gif'/>") no-repeat;cursor: pointer;text-indent: -999em
}.select_opt p#toright {background-position: 2px 0
}.select_opt p#toleft {background-position: 2px -22px
}
</style>
</head>
<body><div class="rounded table"><table width="100%" cellpadding="0" cellspacing="0" border="0" class="box_top"><tbody><tr><td class="title"></td><td></td></tr></tbody></table><div class="error rounded top_error hide"><ol></ol><span></span></div><form:form id="form1" commandName="roleInfo" action="${pageContext.request.contextPath}/u/saveRoleShowField" method="post"><table class="update" cellpadding="0" cellspacing="1" border="0"><tbody><tr class="even"><td>角色名稱: ${roleInfo.roleName }<input type="hidden" name="id" value="${roleInfo.id}" /><input type="hidden"  name="showFields" value="${showFields}" /></td></tr><tr class="even"><td>航班類型:<c:forEach items="${tableNameList}" var="tableName"><c:if test="${tableName  == 'TB_CMS_FLGTINFO_D'}"><input type="radio" class="radio" name="tableName" id="TB_CMS_FLGTINFO_D" value="${tableName }" οnclick="jingchugang(${tableName});" />出港列表</c:if><c:if test="${tableName  == 'TB_CMS_FLGTINFO_A'}"><input type="radio" class="radio" name="tableName" id="TB_CMS_FLGTINFO_A" value="${tableName }" οnclick="jingchugang(${tableName});"/>進港列表</c:if></c:forEach></td></tr><tr class="even"><td>賦予的顯示字段列表:</td></tr><!-- <tr class="even"><td><div id="menuTree"></div></td></tr> --><tr class="even"><td><div class="select_side"><p>待選區</p><select id="selectL" name="selectL" multiple="multiple"></select></div><div class="select_opt"><p id="toright" title="添加">></p><p id="toleft" title="移除"><</p></div><div class="select_side"><p>已選區</p><select id="selectR" name="selectR" multiple="multiple"></select></div><div class="sub_btn"><input type="button" id="sub" value="getValue" /></div></td></tr><%-- <tr class="even"><td>賦予的顯示字段列表:</td></tr><tr class="even"><td><form:checkboxes items="${roleShowEntities }" path="showFields" itemLabel="fieldName" itemValue="id" delimiter=""/></td></tr> --%></tbody></table><table class="table top_line"><tbody><tr><td align="center" height="60"><a id="submit" class="submit"href="javascript:;" οnclick="submitForm();">保存</a></td></tr></tbody></table></form:form></div>
</body>
</html>


本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/443464.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/443464.shtml
英文地址,請注明出處:http://en.pswp.cn/news/443464.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

學習筆記5-C語言-數組

數組&#xff1a; 什么是數組&#xff1a; 相同類型變量的組合,是一種批量定義變量的方式 定義&#xff1a; 類型 數組名[數組變量數量]&#xff1b;int arr[5]; 使用&#xff1a;數組名[下標]&#xff1b;arr[0];數組下標從零開始&#xff0c;范圍&#xff1a;0~數量-1 遍歷…

學習筆記6-小項目-走迷宮、推箱子

獲取方向鍵的功能&#xff1a;使用getch.h頭文件中的getch函數 1、把windows中的getch.h頭文件放到共享文件夾中 2、終端輸入 cd /media/sf_GONGXIANG進入共享文件夾 3、sudo cp getch.h /usr/include 4、cd /usr/include/ 5、sudo chmod r getch.h頭文件中的getch函數 time.h…

學習筆記7-C語言-進制轉換、原返補、位運算、函數

進制轉換 為什么要使用二、八進制、十六進制&#xff1f;因為現在的CPU只能識別高低兩種電流&#xff0c;因此只能對二進制數據進行運算二進制數據雖然可以直接被cpu識別&#xff0c;但不方便人們書寫、記錄&#xff0c;所以把二進制數據轉換成八進制是為了方便記錄在文件中。…

學習筆記8-作業

作業1&#xff1a;實現一個函數&#xff0c;判斷一個整數是否是素數&#xff0c;調用該函數來顯示出100~10000之間的所有素數 #include<stdio.h> #include<stdbool.h> #include<math.h> bool is_sushu(int num) {for(int i2;i<sqrt(num);i){if(num%i0)re…

學習筆記9-C語言-傳參、類型限定符、遞歸

函數傳參&#xff1a; 1、形參變量屬于它所在的函數&#xff0c;出了該函數就不能使用 2、實參與形參之間都是以賦值的形式進行數據傳遞&#xff08;值傳遞&#xff09; 3、return 其實是把返回值數據放置到一個公共的區域&#xff08;函數和函數調用者&#xff09;&#xff0…

Oracle創建視圖實現獲取當前數據所在的頁數,這里以每頁2條數據分頁

摘要&#xff1a;Oracle創建視圖實現獲取當前數據所在的頁數&#xff0c;這里以每頁2條數據分頁&#xff0c;詳細請看&#xff1a; 一&#xff1a; DROP VIEW MIP.TB_CMS_FLGTINFO_D_VIEW;/* Formatted on 2014/12/4 8:35:36 (QP5 v5.115.810.9015) */ CREATE OR REPLACE FOR…

學習筆記10-C語言-小項目-五子棋

小項目&#xff1a; 需要的數據 1、定義棋盤的二維數組 2、定義變量用于記錄下棋的坐標 3、定義角色 黑棋 O 白棋 * 空位業務邏輯&#xff1a; 是否需要對數據初始化 for(;;) {1、清屏、顯示棋盤2、落子坐標是否合法、該位置是否有棋子3、判斷是否五子連珠4、交換角色5、顯示…

學習筆記11-C語言-指針

什么是指針&#xff1a; 指針是一種特護的數據類型&#xff0c;使用它可以定義指針變量&#xff0c;指針變量存儲的是整型數據&#xff0c;代表內存的編號&#xff0c;通過這個編號可以訪問到對應內存。為什么使用指針 1、函數與函數之間是相互獨立的&#xff0c;但是有些時候…

學習筆記12-C語言-堆內存、字符串

什么是堆內存&#xff1a; 是進程中的一個內存段&#xff08;text\data\bss\heap\stack&#xff09;&#xff0c;由程序猿手動控制。 特點是足夠大&#xff0c;缺點是使用麻煩為什么要使用堆內存&#xff1a; 1、隨著程序的復雜&#xff0c;數據會越來越多。 2、其他的內存段…

學習筆記13-C語言-字符串函數、緩沖區

字符串的常用函數: #include<string.h> size_t strlen(const char* s); 功能&#xff1a;計算字符串長度&#xff0c;但是結果不包括\0 返回值&#xff1a;返回字符串中字符的個數size_t str_len(const char* str) {assert(NULL ! str);const char* tmp str;while(*tmp…

Oracle數據庫里面查詢字符串類型的字段不為空和為空的SQL語句:

摘要&#xff1a;近期項目中&#xff0c;在做高級查詢的時候有個條件是根據選擇的字段&#xff0c;然后再選擇字段的值為空和不為空做查詢&#xff0c;在寫SQL語句的時候費了很長時間&#xff0c;現在記錄一下&#xff0c;方便日后查看&#xff1a; 一&#xff1a;查詢字符串類…

學習筆記14-C語言-小項目-通訊錄

通訊錄&#xff1a; 要求&#xff1a; 姓名&#xff0c;性別、電話&#xff0c;最多儲存50個聯系人 功能&#xff1a;1、添加聯系人2、按名字刪除聯系人3、按姓名修改聯系人信息4、查找聯系人&#xff0c;可通過電話&#xff0c;名字查找&#xff0c;支持模糊查找5、顯示所有聯…

學習筆記15-C語言-預處理指令、條件編譯、頭文件

預處理指令&#xff1a; 程序猿編寫的代碼不是標準C代碼&#xff0c;并不能被真正的編譯器索編譯&#xff0c;需要一段程序把代碼翻譯一下。 翻譯的過程叫做預處理&#xff0c;被翻譯的代碼叫做預處理指令&#xff0c;以#開頭的都是預處理指令查看預處理的過程&#xff1a;gcc…

學習筆記16-C語言-小項目-使用Makefile完成2048

Makefile: Makefile是一系列編譯指令組成的可執行文本&#xff0c;也叫做編譯腳本。 在終端執行make命令會自動執行Makefile腳本中的編譯命令&#xff0c; 而且它還可以根據文件的最后修改時間來判斷哪些文件是否需要重新編譯、哪些文件不需要重新編譯&#xff0c;從而大大提高…

學習筆記17-C語言-結構、聯合、枚舉

結構&#xff1a; struct 結構是由程序猿自己設計的一種數據類型&#xff0c;用于描述一個事務的各項數據&#xff0c;由若干個不同的基礎數據類型組成。設計結構&#xff1a;struct 結構體名{類型 成員名&#xff1b;...}&#xff1b;定義結構體變量struct 結構體名 變量名&a…

Maven 3.0.5 安裝和配置:

摘要&#xff1a;現在的Web項目越來越多的都用maven管理了&#xff0c;所以我也抽時間學習學習&#xff0c;為了趕上時代&#xff01; 一&#xff1a;首先到maven官網&#xff1a;http://maven.apache.org/&#xff0c;然后選擇相應的版本下載&#xff0c;我這里下載的是maven…

學習筆記18-C語言-文件

文件的分類&#xff1a; 文本文件&#xff1a; 存儲的是ASCII碼值的二進制 二進制文件&#xff1a; 存儲的是數據的補碼文件IO&#xff1a; FILE *fopen(const char *path, const char *mode); 功能&#xff1a;打開或者創建文件 path&#xff1a;文件的路徑 mode&#x…

使用INNER JOIN ON 多表關聯查詢,獲取指定用戶下指定權限的資源SQL:

摘要&#xff1a;最近在看一個開源框架&#xff0c;其中用戶&#xff0c;角色&#xff0c;資源&#xff0c;這塊我感覺比較重要&#xff0c;所以就自己也模仿著寫了下&#xff0c;其中在獲取指定用戶下的權限資源的時候遇到問題了&#xff0c;開始時&#xff0c;我首先想到的方…

Maven學習記錄之maven基本操作命令,maven本地工廠的創建,maven骨架的生成,以及在eclipse中創建maven工程:...

摘要&#xff1a;今天又學習了一下maven&#xff0c;之前是下載并安裝和配置好了maven的環境&#xff0c;今天主要學習的內容包括&#xff1a;maven本地工廠的創建&#xff0c;maven骨架的生成命令&#xff0c;maven在dos下創建maven工程&#xff0c;以及在eclipse中創建mavne工…

Oracle中通過游標執行帶參數的存儲過程實現解析CLOB字段內的xml字符串:

摘要&#xff1a;近來之前的項目數據出現了問題&#xff0c;原因是由于之前在設計數據庫的時候把時間字段設置成了字符串格式&#xff0c;所以給后期的數據操作帶來了很大的麻煩&#xff0c;這里提醒一下各位程序猿&#xff0c;以后在開發項目的時候時間字段一定要是時間字段&a…