使用多个JavaScript Onload函数

时间:2015-03-30 14:47:17

标签: javascript jquery

我希望在我的网站上为2个特定用户提供2个Onload功能。然而,当我添加第二个OnLoad功能时,单选按钮被禁用,我无法使用它们,任何想法为什么会这样?

 $(window).on('load', function () {
      if (frmUser.User.value != 'SYSTEM') {
            frmUser.textCustomer.style.backgroundColor = '#cccccc';
            frmUser.textCustomer.disabled = true;
            frmUser.textSiteCode.style.backgroundColor = '#cccccc';
            frmUser.textSiteCode.disabled = true;
            frmUser.option.disabled = true;
            frmUser.radioadd.disabled = true;
            frmUser.radiodelete.disabled = true;
        }
            });

 $(window).on('load', function () {
      if (frmUser.User.value != 'TRAINER') {
            frmUser.textCustomer.style.backgroundColor = '#cccccc';
            frmUser.textCustomer.disabled = true;
            frmUser.textSiteCode.style.backgroundColor = '#cccccc';
            frmUser.textSiteCode.disabled = true;
            frmUser.option.disabled = true;
            frmUser.radioadd.disabled = true;
            frmUser.radiodelete.disabled = true;
        }
            });

以下是页面其余部分的代码

<asp:Literal ID="litLoginActionHidden" runat="server" />

<div>
    <table>
    <tr>
    <td style="height: 21px">
    <asp:Literal ID="errormsg" runat="server"/>
   </td>
   </tr>
    </table>
</div>

<form id="frmUser" method="post" action="/Stock/UserMaint?action=update">
   <div class="screentitle">
     <asp:Literal ID="screentitle" runat="server"/>
    </div>
    <div>
    <table>
     <tr>
     <td>
     <asp:HyperLink ID="linkBack" Text=" Back" runat="server" ToolTip="Back" class="ApplicationDefault"  ><img class="ApplicationDefault" alt="Back" src="../../Images/external.png" /></asp:HyperLink>
     </td>
     <td>
     </td>
     <td>
        <asp:image ID="Image1"  runat="server" src="../../Images/save.png" ToolTip="Save" onclick="return SubmitForm()" />
     </td>
     <td style="width: 99%; text-align: right">
        <asp:HyperLink ID="linkBackToMainPage" ToolTip="Log Out" runat="server" class="ApplicationDefault" ><img class="ApplicationDefault" alt="Log out" src="../../Images/door_out.png" /></asp:HyperLink>
     </td>
     </tr>
     </table>
    </div>
<div class='FixedDiv' style="text-align: center; height: 179px;" >
 <asp:HyperLink ID="linkLogin" 
                    Text=" " runat="server" />
    <table cellspacing="5px" cellpadding="0px" style="text-align: center; margin-left:auto; margin-right:auto;" >
      <!-- row 1 -->  
      <tr class='FixedDiv'>

      <td style="width: 65%; height: 124px;"> <!-- left box -->
        <table>
          <tr class='FixedDiv'>
            <td style="width: 20%; height: 15px;"></td>
            <td align = 'left' style="width: 20%; height: 15px;">
                <input id="radioupdate" type="radio" name="option" value="Update" onselect="setUpdateActive()" onclick="setUpdateActive()" checked="checked" />  Update</td>
            <td align = 'left' style="width: 20%; height: 15px;">
                <input id="radioadd" type="radio" name="option" value="Add" onselect="setAddActive()" onclick="setAddActive()" />  Add</td>
            <td align = 'left' style="width: 20%; height: 15px;">
                <input id="radiodelete" type="radio" name="option" value="Add" onselect="setDeleteActive()" onclick="setDeleteActive()" />  Delete</td>
            <td style="width: 20%; height: 15px;"></td>
          </tr>
         <tr class='FixedDiv'>
            <td align = 'left' style="width: 20%; height: 15px;">
                User:</td>
            <td align = 'left' style="width: 20%; height: 15px;">
                <asp:Literal id="litUserMaint" runat="server" />
            </td>
            <td style="width: 20%; height: 15px;"></td>
            <td align = 'left' style="width: 20%; height: 15px;">
                New User:</td>
            <td align = 'left' style="width: 20%; height: 15px;">
              <input disabled="disabled"  style="background-color: #cccccc; width: 151px; height: 15px;" type="text" id="textNewUser" name="textNewUser" />
            </td>
         </tr>
         <tr class='FixedDiv'>
            <td align = 'left' style="width: 20%; height: 15px">
                Password:
            </td>
            <td align = 'left' style="width: 20%; height: 15px">
                <asp:Literal id="litUserPwd1" runat="server" />
               </td>
            <td style="width: 20%; height: 15px;"></td>
            <td align = 'left' style="width: 20%; height: 15px">
                Confirm Password:
            </td>
            <td align = 'left' style="width: 20%; height: 15px">
                <asp:Literal id="litUserPwd2" runat="server" />
            </td>
           </tr>
            <tr class='FixedDiv'>
            <td align = 'left' style="width: 20%; height: 23px">
                Country:
            </td>
            <td align = 'left' style="width: 20%; height: 23px">
              <asp:Literal id="litCountryList" runat="server" />
            </td>
            <td style="width: 20%; height: 23px;"></td>
            <td align = 'left' style="width: 20%; height: 23px">
                Email Address:</td>
            <td align = 'left' style="width: 20%; height: 23px">
                <asp:Literal id="textEmail" runat="server" />&nbsp;
                </td>
                </tr>
                <tr>
                <td align = 'left' style="width: 20%; height: 23px">
                Customer Code:
                </td>
                 <td align = 'left' style="width: 20%; height: 23px">
              <asp:Literal id="litCustomerCode" runat="server" />
            </td>
            <td>
            </td>
            <td align = 'left' style="width: 20%; height: 23px">
                SiteCode:
                </td>
                <td align = 'left' style="width: 20%; height: 23px">
                <asp:Literal id="litSiteCode" runat="server" />
                </td>



                </tr>


                </table>
        </td> 
        </tr>
    <!-- row 1 -->
    </table>
</div>  
</form>

2 个答案:

答案 0 :(得分:0)

if (frmUser.User.value != 'SYSTEM' || frmUser.User.value != 'TRAINER') {
            frmUser.textCustomer.style.backgroundColor = '#cccccc';
            frmUser.textCustomer.disabled = true;
            frmUser.textSiteCode.style.backgroundColor = '#cccccc';
            frmUser.textSiteCode.disabled = true;
            frmUser.option.disabled = true;
            frmUser.radioadd.disabled = true;
            frmUser.radiodelete.disabled = true;
}

答案 1 :(得分:0)

   $(window).on('load', function () {
       if (frmUser.User.value != 'SYSTEM' && !'TRAINER' || frmUser.User.value != 'TRAINER' && !'SYSTEM') {
           frmUser.textCustomer.style.backgroundColor = '#cccccc';
           frmUser.textCustomer.disabled = true;
           frmUser.textSiteCode.style.backgroundColor = '#cccccc';
           frmUser.textSiteCode.disabled = true;
           frmUser.option.disabled = true;
           frmUser.radioadd.disabled = true;
           frmUser.radiodelete.disabled = true;
           }
        });

这让它发挥作用