jquery自動(dòng)填充勾選框即把勾選框打上true
更新時(shí)間:2014年03月24日 17:10:00 作者:
jquery自動(dòng)填充勾選框,即把勾選框打上(true),然后通過ajax方式獲得勾選項(xiàng)列表,再把列表內(nèi)的選項(xiàng)打上
jquery自動(dòng)填充勾選框,即把勾選框打上(true),然后通過ajax方式獲得勾選項(xiàng)列表,再把列表內(nèi)的選項(xiàng)打上。
下拉框<select name="makemodule" id="makemodule" style='width:130px' onchange='makemoduleSelected()'>
<option value='1'>1</option>
</select>
select改變,觸發(fā)函數(shù)makemoduleSelected(),該函數(shù)如下:
//模板下拉框發(fā)生變化時(shí),觸發(fā)此事件(onchange)。
function makemoduleSelected(){
clearAll('property');
var modtitlecode = $("#makemodule").val();
$.ajax({
url : 'indexStatisticsAction_getSelect.jsp',
data: { page:'clientindexStatistics.jsp',method:'get_subname_en',modtitlecode:modtitlecode},
success : function(result){
// 根據(jù)result返回信息判斷是否登錄成功
var results = result.split(",");
//document.getElementById(results[i]).checked = true;
$(".indexStatistics").each(function(){
$(this).find("input").each(function(){
var tempVal = $(this).val();
for(var i=0; i<results.length; i++){
if(tempVal == results[i]) $(this).attr("checked", true);
}
});
});
}
});
}
該函數(shù)通過ajax方式向indexStatisticsAction_getSelect.jsp發(fā)出請(qǐng)求,返回一個(gè)字符串,把改字符串分開成字符串?dāng)?shù)組,接下來遍歷標(biāo)簽<div class="indexStatistics">下面的標(biāo)簽,遇到相關(guān)的標(biāo)簽,則打鉤(true)。indexStatisticsAction_getSelect.jsp的相關(guān)代碼如下:
//獲取模板對(duì)應(yīng)的指標(biāo)
if(method.equals("get_subname_en")){
String modtitlecode = request.getParameter("modtitlecode");
if(modtitlecode.equals("-------")) return;
String sql = sql2.replace("?modtitlecode?",modtitlecode);
sql = sql.replace("?userId?",userId);
System.out.println(sql);
StringBuffer subnames = new StringBuffer();
Db db = new Db();
try {
db.prepareQuery();
ResultSet rs = db.executeQuery(sql);
while (rs!=null && rs.next()) {
subnames.append(rs.getString("subname_en"));
subnames.append(",");
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
db.endQuery();
}
PrintWriter pout = response.getWriter();
pout.write(subnames.toString().substring(0,subnames.length()-1));
pout.flush();
pout.close();
}
復(fù)制代碼 代碼如下:
下拉框<select name="makemodule" id="makemodule" style='width:130px' onchange='makemoduleSelected()'>
<option value='1'>1</option>
</select>
select改變,觸發(fā)函數(shù)makemoduleSelected(),該函數(shù)如下:
復(fù)制代碼 代碼如下:
//模板下拉框發(fā)生變化時(shí),觸發(fā)此事件(onchange)。
function makemoduleSelected(){
clearAll('property');
var modtitlecode = $("#makemodule").val();
$.ajax({
url : 'indexStatisticsAction_getSelect.jsp',
data: { page:'clientindexStatistics.jsp',method:'get_subname_en',modtitlecode:modtitlecode},
success : function(result){
// 根據(jù)result返回信息判斷是否登錄成功
var results = result.split(",");
//document.getElementById(results[i]).checked = true;
$(".indexStatistics").each(function(){
$(this).find("input").each(function(){
var tempVal = $(this).val();
for(var i=0; i<results.length; i++){
if(tempVal == results[i]) $(this).attr("checked", true);
}
});
});
}
});
}
該函數(shù)通過ajax方式向indexStatisticsAction_getSelect.jsp發(fā)出請(qǐng)求,返回一個(gè)字符串,把改字符串分開成字符串?dāng)?shù)組,接下來遍歷標(biāo)簽<div class="indexStatistics">下面的標(biāo)簽,遇到相關(guān)的標(biāo)簽,則打鉤(true)。indexStatisticsAction_getSelect.jsp的相關(guān)代碼如下:
復(fù)制代碼 代碼如下:
//獲取模板對(duì)應(yīng)的指標(biāo)
if(method.equals("get_subname_en")){
String modtitlecode = request.getParameter("modtitlecode");
if(modtitlecode.equals("-------")) return;
String sql = sql2.replace("?modtitlecode?",modtitlecode);
sql = sql.replace("?userId?",userId);
System.out.println(sql);
StringBuffer subnames = new StringBuffer();
Db db = new Db();
try {
db.prepareQuery();
ResultSet rs = db.executeQuery(sql);
while (rs!=null && rs.next()) {
subnames.append(rs.getString("subname_en"));
subnames.append(",");
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
db.endQuery();
}
PrintWriter pout = response.getWriter();
pout.write(subnames.toString().substring(0,subnames.length()-1));
pout.flush();
pout.close();
}
相關(guān)文章
jQuery將表單序列化成一個(gè)Object對(duì)象的實(shí)例
下面小編就為大家?guī)硪黄猨Query將表單序列化成一個(gè)Object對(duì)象的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
jQuery Study Notes學(xué)習(xí)筆記 (二)
jquery簡(jiǎn)單選擇器的使用方法。jquery中最基本的東西了。2010-08-08
基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼,涉及jQuery回調(diào)函數(shù)及頁(yè)面元素屬性動(dòng)態(tài)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
jQuery實(shí)現(xiàn)導(dǎo)航高亮的方法【附demo源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)導(dǎo)航高亮的方法,涉及針對(duì)鼠標(biāo)事件的相應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)變換的相關(guān)操作技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2016-11-11
jQuery實(shí)現(xiàn)的模擬彈出窗口功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的模擬彈出窗口功能,結(jié)合實(shí)例形式分析了jQuery彈出窗口的初始化、坐標(biāo)、背景設(shè)置等相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
jquery實(shí)現(xiàn)簡(jiǎn)單的輪換出現(xiàn)效果實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)簡(jiǎn)單的輪換出現(xiàn)效果,涉及jquery針對(duì)圖片樣式切換效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
jQuery使用正則表達(dá)式限制文本框只能輸入數(shù)字
本文主要介紹jQuery中使用正則表達(dá)式限制文本框只能輸入數(shù)字的功能,希望能幫到大家,有需要的朋友可以參考一下。2016-06-06
jQuery+HTML5實(shí)現(xiàn)圖片上傳前預(yù)覽效果
這篇文章主要介紹了jQuery+HTML5實(shí)現(xiàn)圖片上傳前預(yù)覽效果,涉及jquery操作圖片動(dòng)態(tài)顯示效果,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08
jQuery Mobile漏洞會(huì)有跨站腳本攻擊風(fēng)險(xiǎn)
人們經(jīng)常將跨站腳本攻擊(Cross Site Scripting)縮寫為CSS,但這會(huì)與層疊樣式表(Cascading Style Sheets, CSS)的縮寫混淆。因此有人將跨站腳本攻擊縮寫為XSS。2017-02-02

