/**給element賦值 * @param el * @param val */ public static void setElementValue(Element el,String val){ if(el == null || val == null){ return; } if(el.tagName().equals("select")){ el.children().removeAttr("selected"); for (Element el_option : el.children()) { if(val.equals(el_option.attr("value"))){ el_option.attr("selected","selected"); break; } } }else if(el.attr("type").equals("radio") || el.attr("type").equals("checkbox")){ if(val.equals(el.attr("value"))){ el.attr("checked","checked"); } }else{ el.val(val); } } public static void main(String[] args) { String s = "<input type='checkbox' name='a' value='a'>"+ "<input type='radio' name='a' value='a'>"+ "<select name='b' id='b'><option value='a'>北京</option> <option value='2'>上海</option></select>"; Document doc_data = Jsoup.parse(s); Elements els = doc_data.select("input,textarea,select"); for(Element el : els){ setElementValue(el,"a"); } System.out.println(doc_data.body().html()); }