1. 程式人生 > >js表單反顯

js表單反顯

function checked hidden ttr UNC lec box ati dde

/*
 * 表單自動回顯js
 * 依賴JQURY
 * 使用參考:$("#form1").form("load",{"id":"112","username":"ff","password":"111","type":"admin"}); //id、username、password、type 是 表單 空間name
 */
$(function(){
    $.fn.form=function(type,data){
        var form=$(this);
        for(var i in data){
            var name=i;
            
var value=data[i]; if(name!=""&&value!=""){ valuAtion(name,value); } } function valuAtion(name,value){ if(form.length<1){ return; } if(form.find("[name=‘"+name+"‘]").length<1){
return; } var input=form.find("[name=‘"+name+"‘]")[0]; if($.inArray(input.type,["text","password","hidden","select-one","textarea"])>-1){ $(input).val(value); }else if(input.type==" "||input.type=="checkbox"){ form.find(
"[name=‘"+name+"‘][value=‘"+value+"‘]").attr("checked",true); } } }; });

js表單反顯