MVC3 上的文本框更改更新字段或启用“保存”按钮

发布于 2024-12-19 01:29:08 字数 735 浏览 5 评论 0原文

我有一个 C#.Net MVCV3 Web 应用程序。有一个要求,当用户更改文本框中的文本并跳出文本框时,应用程序需要更新或修改页面标题,通过附加“*”来指示页面需要正在保存.....或者...启用“保存”按钮以指示需要保存页面。我不知道如何在客户端代码中执行此操作而不提交表单。有什么想法吗?

编辑以反映 3nigma 的评论摘要。需要将 keyup 和 Change 函数添加到 Window.Load 事件或 document.ready 事件中:

    $(window).load(function () {
        $("#Description").keyup(function (e) {
            $("input[type='submit']").removeAttr("disabled");
            document.title = document.title + "*";

        });
    });

或者

  $(document).ready(function () {
        $("#Description").keyup(function (e) {
            $("input[type='submit']").removeAttr("disabled");
            document.title = document.title + "*";

        });

    });

I have a C#.Net MVCV3 web app. There is a requirement that, when a user changes the text in a text box and tabs out of the text box, the app needs to update either modify the title of the page by appending a "*" to indicate the page is in need of saving.....OR...enable the Save button to indicate the page needs to be Saved. I don't know how to do this in the client code without submitting the form. Any ideas?

Editting to reflect summary of comments with 3nigma. The keyup and change functions needed to be added to either the Window.Load event or the document.ready event:

    $(window).load(function () {
        $("#Description").keyup(function (e) {
            $("input[type='submit']").removeAttr("disabled");
            document.title = document.title + "*";

        });
    });

OR

  $(document).ready(function () {
        $("#Description").keyup(function (e) {
            $("input[type='submit']").removeAttr("disabled");
            document.title = document.title + "*";

        });

    });

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

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

发布评论

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

评论(2

请持续率性 2024-12-26 01:29:08

您可以使用jquery,在文档准备好时禁用提交按钮,

$(function(){
$("input[type='submit']").attr("disabled","disabled");
});

将更改事件绑定到用户可以更改的字段,例如textbox

$("#TextBoxID").change(function(){    
//enable the submit button here
$("input[type='submit']").removeAttr("disabled");
});

或附加一个*,例如

$("<span/>",{text:"*"}).appendTo("#TextBoxID");

you can use jquery for that, on document ready disable the submit button

$(function(){
$("input[type='submit']").attr("disabled","disabled");
});

bind a change event to the fields that the user can change like textbox

$("#TextBoxID").change(function(){    
//enable the submit button here
$("input[type='submit']").removeAttr("disabled");
});

or append a * like

$("<span/>",{text:"*"}).appendTo("#TextBoxID");
何必那么矫情 2024-12-26 01:29:08

您可以使用以下命令更改页面的标题。
将类似以下内容改编到任何更改功能中。

<script language="javascript">
document.title = document.title + "*";
</script>

You can change the title of the page using the following.
Adapt something like the following into any change functions.

<script language="javascript">
document.title = document.title + "*";
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文