|
|
JQuery Set UnSet Functions
Data: 15-04-2008
Autor: Candido Tominaga
Use estas funcões para preencher e esvaziar os campos do formulário
/*
* SetF - Set values in form fields
* @param selector jquery id : #group , .class p
* @param string|array vv - vv=[1,2,3,4,...]
* PS:
*/
function SetF(id, vv)
{
try {
$(id)[0].type;
}
catch(e) {return}
if(!$(id)[0].type)
{
var type = $("input[@name="+id.replace("#","")+"]")[0].type;
var o = $("input[@name="+id.replace("#","")+"]");
}
else
{
var type = $(id)[0].type;
var o = $(id);
}
if(typeof vv == "string" || typeof vv == "number"){
v = [];
v.push(vv);
}
else v = vv;
switch(type)
{
case "radio":
case "checkbox":
case "select-multiple":
case "select-one":
o.val(v);
break;
default:
o.val(v.join(','));
}
}
/*
* @param slist = Selector List. Ex.: #sel1,#sel2,...
*/
function UnSetF(slist)
{
var l = slist.split(',');
for(var i=0; i < l.length; i++)
{
SetF(l[i],'');
}
}
/**
* Chain function
* Ex.: $("#a,#b,#c").show().UnSetF();
*/
$.fn.UnSetF = function ()
{
$(this).each(function(){
UnSetF("#"+this.id);
})
}
Exemplo
Veja o exemplo em ação:
Exemplo
|