简体   繁体   English

html.textbox javascript / jquery

[英]html.textbox javascript/jquery

I've the below ajax form. 我有下面的ajax表格。 In the form I've got 2 textbox. 在表单中,我有2个文本框。 There is a radio button to choose between Unlock and reset the password. 有一个单选按钮,可以在“解锁”和“重置密码”之间进行选择。 All I want to do here is if I select unlock password label and textbox should disappear. 我要做的就是选择“解锁密码”标签,并且文本框应该消失。 I could do this with below javascript function only if the label and textbox were pure html. 仅当标签和文本框为纯html时,我才可以使用以下javascript函数执行此操作。 If I do that then Ajax doesnot pick up the value of password. 如果我这样做,那么Ajax不会获取密码的值。 Your help is much appreciated. 非常感谢您的帮助。

<input name="rblTooType" value="Unlock" type="radio" checked="checked" onclick="rblToolType_OnChange(true)" />Unlock
<input name="rblTooType" value="reset" type="radio" onclick="rblToolType_OnChange(false)" />reset Password 

@using(Ajax.BeginForm("Search","User",new AjaxOptions { 
                UpdateTargetId = "divResults"      
            })){   
            @Html.Label("UserName")
        @Html.TextBox("term")
        @Html.Label("Password")
        @Html.TextBox("Password")
    <input id="btnSubmit" type="submit" value="Unlock"/>
    }

    <script type="text/javascript">
        function rblToolType_OnChange(isUnlock) {
            if (isUnlock) {
                Password.style.display = "none";
                btnSubmit.value = "Unlock";
            }
            else {
                Password.style.display = "";
                btnSubmit.value = "reset Password";
            }
        }
    </script>

You seem to be depending on an old quirk of IE where element names and ids were added as global variables. 您似乎依赖于IE的一个古怪之处,其中将元素名称和ID作为全局变量添加。 It is bad practice to rely on that because other browsers don't support it (it was a very bad idea from the start). 依靠它是不好的做法,因为其他浏览器不支持它(从一开始这是一个非常糟糕的主意)。 Reference your form elements correctly and it should work. 正确引用表单元素,它应该可以工作。 eg 例如

    function rblToolType_OnChange(isUnlock) {
        var form = document.forms['<form name>']
        if (isUnlock) {
            form.Password.style.display = "none";
            form.btnSubmit.value = "Unlock";
        }
        else {
            form.Password.style.display = "";
            form.btnSubmit.value = "reset Password";
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM