表单中的复选框、单选框、下拉单,在显示数据时,经常要用许多重复的代码才能实现。
有了 jquery,一切变得简单多了。
例如,用jQuery实现已选的栏目,如下图:

代码:
复制代码 代码示例:
$("input[@name=degree][@value={$joinuser.degree}]").attr("
checked",true);
$joinuser.degree为数据库存的value值
插入数据库的值以'|'隔开,如下图:

代码:
复制代码 代码示例:
$.each( "{$joinuser.specialty}".split("|"), function(i, n){
$("input[@id='specialty'][@value='"+n+"']").attr("checked",true);
});