【问题标题】:MvcGrid Checkbox with Textbox not showing the right textbox value带有文本框的 MvcGrid 复选框未显示正确的文本框值
【发布时间】:2019-05-12 06:23:47
【问题描述】:

我有一个场景:

我的 MVCGrid 查看图片:

这是我的 Html Javascript 代码:

 $('#btn_preview_').click(function(){
            Validate()
        });

        function Validate()
        {

            $('.mvcGrid table tr').each(function () {
                if($('.mvcGrid table tr input[name=MyCheckbox]:checkbox').is(':checked')==true)
                {
                    var getText =   $.trim($('.mvcGrid table tr td:eq(2) input[name=textboxRemarks]').val());

                    alert('SID ' + $(this).find('td:eq(1)').text() +  ' getText ' + getText);
                }
                else
                {
                    Alert('Checkbox is unchecked');
                }
            });
        }

附加html代码:

<div class="mvcGrid rowMarginTop">
               @Html.Grid(Model.myData).Columns(columns =>
               {

                   columns.Add(a => a.isF).Encoded(false).Sanitized(false).RenderValueAs(a=>Html.CheckBox("MyCheckbox",a.isF)).Titled("");
                   columns.Add(a => a.SID).Titled("SID");
                   columns.Add(a => a.Remarks).Titled("Remarks").Encoded(false).Sanitized(false).RenderValueAs(a => Html.TextBox("textboxRemarks", a.Rem));

               }).WithPaging(10).Sortable(true).Filterable()
             </div>

我需要做的就是验证复选框是否被选中并且备注不为空。

这个 javascript 代码正在运行,但我的问题是即使在 SID 02 中,备注显示而不是空的。

我的问题是如何获得每个文本框行的正确值?

非常感谢任何建议。

【问题讨论】:

  • 请包含您的html。
  • 感谢@Sumesh TG,这只适用于一个 MVC Grid,一个按钮。唯一的问题是我无法获得文本框的正确值。
  • $(this).parent().find('text box id or class '); 在复选框事件中应用此逻辑
  • 我叫这个Html.TextBox("textboxRemarks", 文本框名称
  • 谢谢@Sumesh TG 我的问题在这里$.trim($('.mvcGrid table tr td:eq(2) input[name=textboxRemarks]').val()); 它总是显示第一行文本框值。

标签: javascript jquery asp.net-mvc mvcgrid.net


【解决方案1】:

$('#btn_preview_').click(function(){
            Validate()
        });

        function Validate()
        {

            $('.mvcGrid table tr').each(function (index,item) {
                if($(this).find(' input[name=MyCheckbox]:checkbox').is(':checked')==true)
                {
                    var getText =   $.trim($(this).find(' input[name=textboxRemarks]').val());

                    alert('SID ' + $(this).find('td:eq('+index+')').text() +  ' getText ' + getText);
                }
                else
                {
                    Alert('Checkbox is unchecked');
                }
            });
        }

试试这个。

【讨论】:

  • 谢谢你让我试试。
  • @VijunavVastivch 欢迎,如果您再次遇到任何问题,请告诉我。
  • 代码已经停到$.trim($(this).find(' input[name=textboxRemarks]').val()); my offtime for now. I will review it tommorow. Thanks
  • @VijunavVastivch 好的,使用index 参数应用您的逻辑,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-25
  • 1970-01-01
相关资源
最近更新 更多