创建控件并关联事件
function CreateProductModule(obj){
var SelectProductModule = $("HidSelectProductModule");
if(obj.checked)
{
if(SelectProductModule.value.indexOf(obj.value) == -1)
{
var cb = createCheckbox(obj.value,"SelectProduct");
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = obj.value;
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("ProductType").appendChild(div);
cb.checked = true;
SelectProductModule.value += SelectProductModule.value == ""?obj.value:","+obj.value;
}
}
else
{
var Selpm = SelectProductModule.value.split(",");
$("ProductType").innerHTML = "";
SelectProductModule.value = "";
for(var i=0;i<Selpm.length;i++)
{
if(Selpm[i] != obj.value)
{
var cb = createCheckbox(Selpm[i],"SelectProduct");
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = Selpm[i];
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("ProductType").appendChild(div);
cb.checked = true;
SelectProductModule.value += SelectProductModule.value == ""?Selpm[i]:","+Selpm[i];
}
}
}
}
//机型
function SetProModelOption(brand){
if(brand=="请选择")
$("PolicyInfo").value=userArea;
else
$("PolicyInfo").value=userArea+"_"+brand;
$("SelectProductType").innerHTML = "";
var fn = function()
{
CreateProductModule(this);
}
var res = MakePolicy.GetProductModelByUser(brand);
var promodel = MakePolicy.GetModelByAreaAndBrandAndState(brand);
if(res.value != null ){
for(var i=0; i<res.value.length; i++){
for(var j=0;j<promodel.value.length;j++){
if(res.value[i].ProductModel==promodel.value[j].ProductModel){
var cb = createCheckbox(res.value[i].ProductModel,"SelectProduct");
cb.onclick=fn;
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = res.value[i].ProductModel;
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("SelectProductType").appendChild(div);
break;
}
}
}
}
}
以上代码作用是:用户选择一个手机品牌后构造手机机型的多选列表并使复选框关联到一个方法,这个方法来添加或删除不同品牌下选中的多个机型.
var SelectProductModule = $("HidSelectProductModule");
if(obj.checked)
{
if(SelectProductModule.value.indexOf(obj.value) == -1)
{
var cb = createCheckbox(obj.value,"SelectProduct");
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = obj.value;
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("ProductType").appendChild(div);
cb.checked = true;
SelectProductModule.value += SelectProductModule.value == ""?obj.value:","+obj.value;
}
}
else
{
var Selpm = SelectProductModule.value.split(",");
$("ProductType").innerHTML = "";
SelectProductModule.value = "";
for(var i=0;i<Selpm.length;i++)
{
if(Selpm[i] != obj.value)
{
var cb = createCheckbox(Selpm[i],"SelectProduct");
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = Selpm[i];
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("ProductType").appendChild(div);
cb.checked = true;
SelectProductModule.value += SelectProductModule.value == ""?Selpm[i]:","+Selpm[i];
}
}
}
}
//机型
function SetProModelOption(brand){
if(brand=="请选择")
$("PolicyInfo").value=userArea;
else
$("PolicyInfo").value=userArea+"_"+brand;
$("SelectProductType").innerHTML = "";
var fn = function()
{
CreateProductModule(this);
}
var res = MakePolicy.GetProductModelByUser(brand);
var promodel = MakePolicy.GetModelByAreaAndBrandAndState(brand);
if(res.value != null ){
for(var i=0; i<res.value.length; i++){
for(var j=0;j<promodel.value.length;j++){
if(res.value[i].ProductModel==promodel.value[j].ProductModel){
var cb = createCheckbox(res.value[i].ProductModel,"SelectProduct");
cb.onclick=fn;
var span = document.createElement("span");
var div= document.createElement("DIV");
span.innerHTML = res.value[i].ProductModel;
div.className = "product";
div.appendChild(cb);div.appendChild(span);$("SelectProductType").appendChild(div);
break;
}
}
}
}
}