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獲取復(fù)選框checkbox的值的簡(jiǎn)單實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猨query獲取復(fù)選框checkbox的值的簡(jiǎn)單實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05基于jQuey實(shí)現(xiàn)鼠標(biāo)滑過變色(整行變色)
相信大家在一些網(wǎng)站都看到過這種效果吧,當(dāng)鼠標(biāo)放在新聞列表一行的時(shí)候,整行就會(huì)變色,雖然使用CSS也能夠?qū)崿F(xiàn)此種功能,但是由于眾多瀏覽器版本對(duì)于CSS3并沒有良好的支持,所以在當(dāng)前情況下,使用jQuery實(shí)現(xiàn)此種功能是一個(gè)不錯(cuò)的選擇2015-12-12關(guān)于query Javascript CSS Selector engine
本篇文章,小編將為大家介紹,關(guān)于query Javascript CSS Selector engine,有需要的朋友可以參考一下2013-04-04vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼
這篇文章主要介紹了vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07jQuery實(shí)現(xiàn)的分子運(yùn)動(dòng)小球碰撞效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)的分子運(yùn)動(dòng)小球碰撞效果,涉及jQuery基于定時(shí)函數(shù)操作頁面元素動(dòng)態(tài)變換的技巧,需要的朋友可以參考下2016-01-01基于daterangepicker日歷插件使用參數(shù)注意的問題
下面小編就為大家?guī)硪黄赿aterangepicker日歷插件使用參數(shù)注意的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08jQuery模仿阿里云購買服務(wù)器選擇購買時(shí)間長(zhǎng)度的代碼
jQuery仿阿里云購買服務(wù)器選擇時(shí)間長(zhǎng)度,操作簡(jiǎn)單,只需點(diǎn)擊所要選的時(shí)間段,對(duì)實(shí)現(xiàn)代碼感興趣的朋友參考下2016-04-04