欢迎来到代码驿站!

jquery

当前位置:首页 > 网页前端 > jquery

jquery自动填充勾选框即把勾选框打上true

时间:2021-04-16 08:24:00|栏目:jquery|点击:
jquery自动填充勾选框,即把勾选框打上(true),然后通过ajax方式获得勾选项列表,再把列表内的选项打上。
复制代码 代码如下:

下拉框<select name="makemodule" id="makemodule" style='width:130px' onchange='makemoduleSelected()'>
<option value='1'>1</option>
</select>

select改变,触发函数makemoduleSelected(),该函数如下:
复制代码 代码如下:

//模板下拉框发生变化时,触发此事件(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){
// 根据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);
}
});
});
}
});
}

该函数通过ajax方式向indexStatisticsAction_getSelect.jsp发出请求,返回一个字符串,把改字符串分开成字符串数组,接下来遍历标签<div class="indexStatistics">下面的标签,遇到相关的标签,则打钩(true)。indexStatisticsAction_getSelect.jsp的相关代码如下:
复制代码 代码如下:

//获取模板对应的指标
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();
}

上一篇:jQuery经过一段时间自动隐藏指定元素的方法

栏    目:jquery

下一篇:jQuery实现查看图片功能

本文标题:jquery自动填充勾选框即把勾选框打上true

本文地址:http://www.codeinn.net/misctech/102241.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有