文本框的值在jQuery模式框中粘贴 [英] Value of text box sticks in jQuery modal box

查看:69
本文介绍了文本框的值在jQuery模式框中粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好



我对Javascript和jQuery的世界都很陌生,所以我希望这是一个简单的修复...



我有一个MVC应用程序。在这个应用程序中,我有一个部分视图,当在其上方的表格中进行选择时,它将被填充。



用户需要能够添加注释到记录,所以有一个按钮打开一个jQuery对话框。



Hi Guys

I'm quite new to the world of Javascript and jQuery, so I'm hoping this is a simple fix...

I have an MVC app. In this app I have a partial view that gets populated when a selection is made in a table above it.

The user needs to be able to add a note to a record, so there is a button that opens a jQuery dialog box.

<div id="dialog-notes" style="display:none;" title="Additional Notes">
     @Html.TextAreaFor(x => x.AdditionalNotes, new { id = "txtNotes" })
     @Html.HiddenFor(x => x.AdditionalNotes)
</div>





当用户输入一些文本并单击确定时,会调用一个操作来保存信息。





When the user enters some text and clicks OK, an action is called to save the info.

<script>
function dialog(dialogBox) {
                $(dialogBox).dialog({
                    modal: true,
                    buttons: {
                        Ok: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            };

            function dialog_notes() {
                $('#dialog-notes').dialog({
                    modal: true,
                    buttons: {
                        Ok: function () {
                            var message = $('#txtNotes').val();
                            var jobID = $('#JobID').val();

                            $.ajax({
                                type: "POST",
                                url: "/Agents/SaveAditionalNotes",
                                data: { jobID: jobID, notes: message },
                                success: function (result) {
                                    dialog('#dialog-notesSaved');
                                },
                                error: function (req, status, error) {
                                    dialog('#dialog-notesSavedFailed');
                                }
                            });
                            $(this).dialog("close");

                        }
                    }
                });
            };
</script> 





乐趣的动作代码:



Action code for fun:

public ActionResult SaveAditionalNotes(int jobID, string notes)
       {
           Listings list = new Listings();

           return Json(list.SaveAdditionalNotes(jobID, notes));
       }





现在,第一次工作正常。但是,如果我在网格中进行另一个选择,再次打开模态对话框,键入新的内容并单击确定,第一次发送文本框的结果将被发送???



示例:第一次值为Sausages。第二次我输入值Mashed Potato。价值香肠将被发送而不是土豆泥...



这是非常困惑的...这是正常行为吗?我怎么阻止这个?



提前谢谢你。



Now, this works fine first time round. However, if I make another selection in the grid, open up the modal dialog again, type something new and click OK, the result from the textbox of the first time is sent???

Example: First time the value is "Sausages". Second time I type the value "Mashed Potato". The value "Sausages" will be sent instead of "Mashed Potato"...

This has be very confused... Is this normal behavior? How do I stop this?

Thank you in advance.

推荐答案

(dialogBox).dialog( {
modal: true
button:{
Ok: function (){
(dialogBox).dialog({ modal: true, buttons: { Ok: function () {


this )。dialog( close);
}
}
});
};

function dialog_notes(){
(this).dialog("close"); } } }); }; function dialog_notes() {


' #dialog-notes')。dialog({
modal: true
按钮:{
好​​:功能(){
var message =
('#dialog-notes').dialog({ modal: true, buttons: { Ok: function () { var message =


这篇关于文本框的值在jQuery模式框中粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆