jquery自動填充勾選框即把勾選框打上true
更新時間:2014年03月24日 17:10:00 作者:
jquery自動填充勾選框,即把勾選框打上(true),然后通過ajax方式獲得勾選項列表,再把列表內(nèi)的選項打上
jquery自動填充勾選框,即把勾選框打上(true),然后通過ajax方式獲得勾選項列表,再把列表內(nèi)的選項打上。
下拉框<select name="makemodule" id="makemodule" style='width:130px' onchange='makemoduleSelected()'>
<option value='1'>1</option>
</select>
select改變,觸發(fā)函數(shù)makemoduleSelected(),該函數(shù)如下:
//模板下拉框發(fā)生變化時,觸發(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ā)出請求,返回一個字符串,把改字符串分開成字符串?dāng)?shù)組,接下來遍歷標(biāo)簽<div class="indexStatistics">下面的標(biāo)簽,遇到相關(guān)的標(biāo)簽,則打鉤(true)。indexStatisticsAction_getSelect.jsp的相關(guān)代碼如下:
//獲取模板對應(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ā)生變化時,觸發(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ā)出請求,返回一個字符串,把改字符串分開成字符串?dāng)?shù)組,接下來遍歷標(biāo)簽<div class="indexStatistics">下面的標(biāo)簽,遇到相關(guān)的標(biāo)簽,則打鉤(true)。indexStatisticsAction_getSelect.jsp的相關(guān)代碼如下:
復(fù)制代碼 代碼如下:
//獲取模板對應(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的值的簡單實現(xiàn)方法
下面小編就為大家?guī)硪黄猨query獲取復(fù)選框checkbox的值的簡單實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05
基于jQuey實現(xiàn)鼠標(biāo)滑過變色(整行變色)
相信大家在一些網(wǎng)站都看到過這種效果吧,當(dāng)鼠標(biāo)放在新聞列表一行的時候,整行就會變色,雖然使用CSS也能夠?qū)崿F(xiàn)此種功能,但是由于眾多瀏覽器版本對于CSS3并沒有良好的支持,所以在當(dāng)前情況下,使用jQuery實現(xiàn)此種功能是一個不錯的選擇2015-12-12
關(guān)于query Javascript CSS Selector engine
本篇文章,小編將為大家介紹,關(guān)于query Javascript CSS Selector engine,有需要的朋友可以參考一下2013-04-04
vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼
這篇文章主要介紹了vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07
基于daterangepicker日歷插件使用參數(shù)注意的問題
下面小編就為大家?guī)硪黄赿aterangepicker日歷插件使用參數(shù)注意的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
jQuery模仿阿里云購買服務(wù)器選擇購買時間長度的代碼
jQuery仿阿里云購買服務(wù)器選擇時間長度,操作簡單,只需點擊所要選的時間段,對實現(xiàn)代碼感興趣的朋友參考下2016-04-04

