function bindData(data,id){
var listener = {};
id = id || "";
$((id != "" ? "#" + id : "") + " input,select,textarea").each(function(i,item){
if($(item).attr("id") != null || $(item).is("input[type='radio'],input[type='checkbox']")){
var dataName = $(item).attr("id");
if($(item).is("input[type='radio'],input[type='checkbox']")){
dataName = $(item).attr("name");
}
data[dataName] = "";
listener[dataName] = {
get: function() {
var value = $(item).val();
if($(item).is("input[type='radio']")){
value = $(":radio[name='"+$(item).attr("name")+"']:checked").val();
}else if($(item).is("input[type='checkbox']")){
value = [];
$(":checkbox[name='"+$(item).attr("name")+"']:checked").each(function(i,v){
value[i] = $(v).val();
});
}
// parent.layer.msg("get:" + dataName + "的值为:" + value);
return value;
},
set: function(value) {
if($(item).is("input[type='radio']")){
$(":radio[name='"+$(item).attr("name")+"']").removeAttr("checked");
$(":radio[name='"+$(item).attr("name")+"'][value='"+value+"']").click();
}else if($(item).is("input[type='checkbox']")){
value = (value == 0 || (value.length == 1 && value[0] == 0)) ? [,0] : value;
$(":checkbox[name='"+$(item).attr("name")+"']").removeAttr("checked");
$(value).each(function(i,v){
$(":checkbox[name='"+$(item).attr("name")+"'][value='"+v+"']").click();
});
}else{
$(item).val(value);
}
// parent.layer.msg("set:" + dataName + "的值变更为:" + value);
}
};
}
});
Object.defineProperties(data, listener);
}