jQuery 选择器的设置值未定义

Setting value of jQuery selector is undefined

我希望能够在用户模式对话框中清除某些 jQuery 输入对象的值。

当用户在对话框中输入数据并使用关闭或提交按钮,然后下次用户编辑另一条记录时,输入字段的先前值仍在表单上。

调试时,jQuery选择器的值为'undefined'。

我以为是因为我在 $(document).ready 函数之前使用它,但是在调试时,我确保这段代码在 DOM 加载之前不会执行。

如何清除输入控件的内容以供用户下次使用?

下面是我的相关 HTML

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>
        $(document).ready(function ()
        {
            if (typeof contentPageLoadOtherDeptsTransfer == "function") contentPageLoadOtherDeptsTransfer();
        });
    </script>

<div class="modal fade" id="btnOtherDeptsTransferEditGrid" tabindex="-1" role="dialog" aria-labelledby="btnOtherDeptsTransferEditGrid-label" aria-hidden="true">
                                                <div class="modal-dialog">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                                            <h4 class="modal-title" id="btnOtherDeptsTransferEditGrid-label">Edit Other Depts Transfer</h4>
                                                        </div>
                                                        <div class="modal-body">
                                                            <div class="modal-body">
                                                                <div class='form-group'>
                                                                    <label class="required col-lg-1 control-label" for="txtOtherDeptsTransferStatusComments">No controls in PowerPoint:</label>
                                                                    <div class="col-lg-9 col-lg-offset-1">
                                                                        <textarea id="txtOtherDeptsTransferStatusComments" rows="5" cols="80" class="form-control"></textarea>
                                                                    </div>
                                                                </div>
                                                                <div class="hide-text">
                                                                    <input type="hidden" id="txtOtherDeptsTransferEditGridID" />
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="submit" id="btnOtherDeptsTransferAccept" class="btn btn-success">Accept</button>
                                                            <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
</asp:Content>

这是我的相关 JS:

function contentPageLoadOtherDeptsTransfer()
{

    // Clear fields in Dialog box before dialog is shown............................//
    $('#btnOtherDeptsTransferEditGrid').on('show.bs.modal', function ()
    {
        $('txtOtherDeptsTransferStatusComments').val("");
    })
}
$('txtOtherDeptsTransferStatusComments').val("");

在'txt'

前加一个#

$('#txtOtherDeptsTransferStatusComments').val("");