js运行到这一步 opener.selectCust(selectText,selectValue);报错,但是我已经定义了function selectCust() {}为什么啊,始终找不出原因

解决方案 »

  1.   

    function selectCustOk(){
    var selectedcust = document.getElementById('selectedcust');
    var selectText = "";
    var selectValue = "";

    for(var i=0; i<selectedcust.options.length; i++){
    var temp = selectedcust.options[i].text.split('|');
    if(selectText == ""){
    selectText = temp[1];//selectedcust.options[i].text;
    } else {
    selectText = selectText + "," + temp[1];//selectedcust.options[i].text;
    }
    if(selectValue == ""){
    selectValue = selectedcust.options[i].value;
    } else {
    selectValue = selectValue + "," + selectedcust.options[i].value;
    }
    }
    opener.selectCust(selectText,selectValue);
    window.close();
    }function unSelectCust(){
    var unselectedcust = document.getElementById('unselectedcust');
    if(!unselectedcust){
    var htmlStr = '<select name="unselectedcust" multiple="multiple" style="width: 100%" size="20" ondblclick="dbClick(this);"></select>';
    var norecd = document.getElementById("norecd");
    norecd.innerHTML = htmlStr;
    unselectedcust = document.getElementById('unselectedcust');
    }
    var selectedcust = document.getElementById('selectedcust');
    if(selectedcust.selectedIndex == -1){
    return;
    }
    for(var i=0; i<selectedcust.options.length; i++){
    var selectText = selectedcust.options[i].text;
    var selectValue = selectedcust.options[i].value; if(selectValue==""){
    selectedcust.options[i].selected = false;
    continue;
    }
    if(selectedcust.options[i].selected){
    var length = unselectedcust.options.length;
    unselectedcust.options.add(new Option(selectText,selectValue));
    unselectedcust.options[length].selected = true;
    selectedcust.options.remove(i--);
    }
    }
    }
      

  2.   


    function selectCust() {
    var unselectedcust = document.getElementById('unselectedcust');
    var selectedcust = document.getElementById('selectedcust');
    if(unselectedcust.selectedIndex == -1){
    return;
    }
    for(var i=0; i<unselectedcust.options.length; i++){
    var selectText = unselectedcust.options[i].text;
    var selectValue = unselectedcust.options[i].value;
    if(selectValue==""){
    unselectedcust.options[i].selected = false;
    continue;
    }
    if(unselectedcust.options[i].selected){
        //判断是否存在    
         for(var j=0; j<selectedcust.options.length;j++){
    var exsitValue = selectedcust.options[j].value;
    if(selectValue == exsitValue) {
         return false;
    }     
         }
        
    var length = selectedcust.options.length;
    selectedcust.options.add(new Option(selectText,selectValue));
    selectedcust.options[length].selected = true;
    unselectedcust.options.remove(i--);
    }
    }
    }
      

  3.   

    恩,是可以。
    为啥不直接调用,而用opener.呢,这个好像不行。
      

  4.   

    opener是个啥东西?selectCust方法是你单独定义的,相当于一个静态方法,并不属于任何一个对象的propertype,要是要这样写,先这样
    opener.selectCust=function(){...}然后再这么调用
      

  5.   

    命名改一下:function selectCust() {}---》function ChooseCust() {}