Jquery數據複製

function copyValue(src,target){
$(src).find("span").each(function(){
var span = this;
var srcName = $(span).attr("name");
if(srcName != undefined){
var text = $(span).text();
$(target).find("span").each(function(){
var targetName = $(this).attr("name");
if(srcName == targetName){
$(this).text(text);
}
})
}
});
$(src).find("input").each(function(){
var input = this;
var srcName = $(input).attr("name");
if(srcName != undefined){
$(target).find(":input").each(function(){
var targetName = $(this).attr("name");
var type = $(this).attr("type");
if(srcName == targetName && "boeLineId" != targetName){
if(type == 'checkbox' || type == 'radio'){
var checked = input.checked;
$(this).attr("checked",checked);
}else{
var value = $(input).val();
$(this).val(value);
}
}
});
}
});
$(src).find("select").each(function(){
var select = this;
var srcName = $(select).attr("name");
if(srcName != undefined){
$(target).find("select").each(function(){
var targetName = $(this).attr("name");
if(srcName == targetName){
var srcValue =  $(select).val(); 
$(this).find("option").each(function(){
var targetValue = $(this).val();
if(srcValue == targetValue){
$(this).attr("selected",true);
}
});
}
});
}
});
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章