psasScripts.js:74未捕获的TypeError:lstFrom.options不是函数

时间:2018-08-17 20:16:44

标签: javascript asp.net google-chrome

  

psasScripts.js:74未捕获的TypeError:lstFrom.options不是   在moveSupplier的moveListboxItems函数   HTMLInputElement.onclick。

这在IE11中工作正常,但是当我尝试在Chrome或其他浏览器中运行它时,出现上述错误,为什么?我认为这可能是可变范围,但我不确定。我试过在JavaScript.js中声明变量,但是它也不起作用。任何帮助将不胜感激。

JavaScript.js:

function moveListboxItems(lstFrom, lstTo, moveAll) {

//alert(lstFrom.value);
if ((moveAll == 1) || (moveAll == true)) {
    //add all items to "To" list box
    for (i = 0; i < lstFrom.length; i++) {
        //alert(lstFrom.length);
        var objOption = document.createElement("OPTION");
        objOption.value = lstFrom.options[i].value;
        objOption.text = lstFrom.options[i].text;

        //alert(objOption.text);
        lstTo.add(objOption);
    }

    //remove all items from "From" list box
    lstFrom.options.length = 0;
}
else {
    //add selected items to "To" list box
    for (i = 0; i < lstFrom.length; i++) {
        if (lstFrom.options[i].selected) {
            //alert(lstFrom.length);
            var objOption = document.createElement("OPTION");

            objOption.value = lstFrom.options[i].value;
            objOption.text = lstFrom.options[i].text;

            //alert(objOption.text);
            lstTo.add(objOption);

            //remove selected items from "From" list box
            lstFrom.remove(lstFrom.selectedIndex);

            i--;
        }
    }
  }
}

payment.aspx

function movePayer(buttonClicked) {
        if (buttonClicked == document.getElementById("<%= ButtonSelectOnePayer.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxFromPayers.ClientID %>"), document.getElementById("<%= ListBoxToPayers.ClientID %>"), 0);
        }
        if (buttonClicked == document.getElementById("<%= ButtonSelectAllPayer.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxFromPayers.ClientID %>"), document.getElementById("<%= ListBoxToPayers.ClientID %>"), 1);
        }
        if (buttonClicked == document.getElementById("<%= ButtonRemoveOnePayer.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxToPayers.ClientID %>"), document.getElementById("<%= ListBoxFromPayers.ClientID %>"), 0);
        }
        if (buttonClicked == document.getElementById("<%= ButtonRemoveAllPayer.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxToPayers.ClientID %>"), document.getElementById("<%= ListBoxFromPayers.ClientID %>"), 1);
        }
    }
//-----------------------------------------------------------------------------------
    function moveSupplier(buttonClicked) {
        if (buttonClicked == document.getElementById("<%= ButtonSelectOneSupplier.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxFromSuppliers.ClientID %>"), document.getElementById("<%= ListBoxToSuppliers.ClientID %>"), 0);
        }
        if (buttonClicked == document.getElementById("<%= ButtonSelectAllSupplier.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxFromSuppliers.ClientID %>"), document.getElementById("<%= ListBoxToSuppliers.ClientID %>"), 1);
        }
        if (buttonClicked == document.getElementById("<%= ButtonRemoveOneSupplier.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxToSuppliers.ClientID %>"), document.getElementById("<%= ListBoxFromSuppliers.ClientID %>"), 0);
        }
        if (buttonClicked == document.getElementById("<%= ButtonRemoveAllSupplier.ClientID %>")) {
            moveListboxItems(document.getElementById("<%= ListBoxToSuppliers.ClientID %>"), document.getElementById("<%= ListBoxFromSuppliers.ClientID %>"), 1);
        }
    }

<td style="width:280px">
                            <asp:listbox id="ListBoxFromPayers" runat="server" cssclass="listbox" tabIndex="7" selectionmode="Multiple" Width="280" Height="150"></asp:listbox>
                        </td>
                        <td style="width:50px; text-align:center">
                            <input type="button" id="ButtonSelectOnePayer" runat="server" class="smallbutton" tabIndex="8" value=">" onclick="movePayer(this);"> 
                            <input type="button" id="ButtonSelectAllPayer" runat="server" class="smallbutton" tabIndex="9" value=">>" onclick="movePayer(this);"> 
                            <input type="button" id="ButtonRemoveOnePayer" runat="server" class="smallbutton" tabIndex="10" value="<" onclick="movePayer(this);"> 
                            <input type="button" id="ButtonRemoveAllPayer" runat="server" class="smallbutton" tabIndex="11" value="<<" onclick="movePayer(this);">
                        </td>   
                        <td style="width:280px">
                            <asp:listbox id="ListBoxToPayers" runat="server" cssclass="listbox" tabIndex="12" selectionmode="Multiple" Width="280" Height="150"></asp:listbox>
                        </td>
                        <td class="td_asterisk">*</td>
<td style="width:280px">
                            <asp:listbox id="ListBoxFromSuppliers" runat="server" cssclass="listbox" tabIndex="13" Width="280" selectionmode="Multiple" Height="150"></asp:listbox>
                        </td>
                        <td style="width:50px; text-align:center">
                            <input type="button" id="ButtonSelectOneSupplier" runat="server" class="smallbutton" tabIndex="14" value=">" onclick="moveSupplier(this);"> 
                            <input type="button" id="ButtonSelectAllSupplier" runat="server" class="smallbutton" tabIndex="15" value=">>" onclick="moveSupplier(this);"> 
                            <input type="button" id="ButtonRemoveOneSupplier" runat="server" class="smallbutton" tabIndex="16" value="<" onclick="moveSupplier(this);"> 
                            <input type="button" id="ButtonRemoveAllSupplier" runat="server" class="smallbutton" tabIndex="17" value="<<" onclick="moveSupplier(this);">
                        </td>
                        <td style="width:280px">
                            <asp:listbox id="ListBoxToSuppliers" runat="server" cssclass="listbox" tabIndex="18" Width="280" selectionmode="Multiple" Height="150"></asp:listbox>
                        </td>
                        <td class="asterisk_nowidth" style="width:20px">&nbsp;*</td>

0 个答案:

没有答案