html.textbox javascript/jquery

发布于 2024-10-31 01:19:39 字数 1147 浏览 1 评论 0原文

我有下面的ajax表单。在表单中我有 2 个文本框。有一个单选按钮可以在解锁和重置密码之间进行选择。我在这里想做的是,如果我选择解锁密码标签,文本框应该消失。仅当标签和文本框是纯 html 时,我才可以使用下面的 javascript 函数来执行此操作。如果我这样做,Ajax 就不会获取密码的值。非常感谢您的帮助。

<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>

I've the below ajax form. In the form I've got 2 textbox. 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. If I do that then Ajax doesnot pick up the value of password. 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浴红衣 2024-11-07 01:19:39

您似乎依赖于 IE 的一个老怪癖,其中元素名称和 id 被添加为全局变量。依赖它是不好的做法,因为其他浏览器不支持它(从一开始这就是一个非常糟糕的主意)。正确引用您的表单元素,它应该可以工作。例如

    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";
        }
    }

You seem to be depending on an old quirk of IE where element names and ids were added as global variables. 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. e.g.

    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";
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文