jsoup操作模板代码,给radio select input 赋值,以及select回显
来源:互联网 发布:沈阳淘宝代运营公司 编辑:程序博客网 时间:2024/06/06 14:14
以下代码仅作参考
LoanSign loanSign = loanSignService.getById(loanSignId);
BorrowTemplate borrowTemplate = borrowTemplateService.getById(loanSign.getBorrowTemplate().getId());
String json = loanSign.getParamsJson(); // 获取json格式字符串
String template = borrowTemplate.getTempHtml(); // 获取模板Html
Document doc = Jsoup.parse(template); // 开始进行操作
// 1.给input[type=text]赋值
Element content = null;
String k ="";
List<String> v = new ArrayList<String>();
//1.1获取select标签的name集合
List<String> selectNames = new ArrayList<String>();
Elements selects = doc.select("select");
for (Element select : selects) {
selectNames.add(select.attr("name"));
}
//1.2获取input[type=radio]标签的name集合
List<String> radioNames = new ArrayList<String>();
Elements radios = doc.select("input[type=radio]");
for (Element radio : radios) {
String name = radio.attr("name");
if(!radioNames.contains(name)){
radioNames.add(name);
}
}
//1.3声明selectMap 和 radioMap
Map<String,List<String>> selectMap = new HashMap<String,List<String>>();
Map<String,List<String>> radioMap = new HashMap<String,List<String>>();
if(StringUtils.hasLength(json)){
Map<String, Object> map = JsonUtil.jsonToMap(json);
for(Entry<String, Object> e: map.entrySet()){
k = e.getKey();
v = (List<String>) e.getValue();
// 拦截select标签
if(selectNames.contains(k)){
selectMap.put(k, v);
continue;
}
// 拦截input[type=radio]标签
if(radioNames.contains(k)){
radioMap.put(k, v);
continue;
}
// 给input[type=text]赋值
content = doc.getElementById(k);
if(content!=null){
content.val(v.get(0));
}
}
}
//2.给select进行赋值
List<DictValue> educationList = this.dictValueService.findDictValueListByKey(DictValueEnum.EDUCATIONBACK);
List<DictValue> comDicList = this.dictValueService.findDictValueListByKey(DictValueEnum.COMPANYTYPE);
for (String name : selectNames) {
//
List<String> value = selectMap.get(name);
String val = "";
if(value!=null && value.size()>0){
val = value.get(0);
}
StringBuffer option = new StringBuffer();
// 学历
if("education".equals(name)){
for (DictValue d : educationList) {
if(val.equals(d.getName())){
option.append("<option selected='selected' value='"+d.getName()+"'>"+d.getName()+"</option>");
}else{
option.append("<option value='"+d.getName()+"'>"+d.getName()+"</option>");
}
}
}
// 企业类型
if("companyType".equals(name)){
for (DictValue d : comDicList) {
if(val.equals(d.getName())){
option.append("<option selected='selected' value='"+d.getName()+"'>"+d.getName()+"</option>");
}else{
option.append("<option value='"+d.getName()+"'>"+d.getName()+"</option>");
}
}
}
Elements e = doc.select("select[name="+name+"]");
e.html(option.toString());
}
//3.给input[type=raio]选中
for (String name : radioNames) {
Elements elements = doc.select("input[name="+name+"]");
List<String> value = radioMap.get(name);
for (Element e : elements) {
String val = e.val();
if(value!=null && value.size()>0 && StringUtils.hasLength(val)){
if(val.equals(value.get(0))){
e.attr("checked","checked");
}
}
}
}
model.put("loanSignId", loanSignId);
model.put("templateHtml", doc.toString());
操作结果
- jsoup操作模板代码,给radio select input 赋值,以及select回显
- select radio 赋值
- radio select checkbox 操作
- jQuery 操作 html 元素的例子 (input/select/checkbox/radio)
- jquery操作input、select、checkbox、radio常用方法
- jquery操作input、select、checkbox、radio常用方法
- jquery操作input、select、checkbox、radio常用方法
- Jquery操作Input之Select和Radio选中
- 给select赋值
- Jquery 给select 赋值
- 给Select标签赋值
- js给select赋值
- 动态给select赋值
- jquery select input:radio input:checkbox
- Jquery操作radio,checkbox,select表单操作实现代码
- Jquery操作radio,checkbox,select表单操作实现代码
- Jquery操作radio,checkbox,select表单操作实现代码
- Jquery操作radio,checkbox,select表单操作实现代码
- 关于 推荐系统方面的一些顶会顶刊
- laravel框架实现phpExcel导入导出
- 管理员你好
- 下载app链接
- LinkedHashMap保证MAP按照插入的顺序输出
- jsoup操作模板代码,给radio select input 赋值,以及select回显
- JDBD的PreparedStatement使用like
- macOs 10.12.2总于修复鼠标驱动了
- php中文件的处理
- xcode6.1新建一个ios程序,为什么自动运行viewController这个类
- Oracle用户、权限、角色管理
- 键值对RDD
- 当spring 容器初始化完成后执行某个方法
- 解析 GetRerootedSIL