【问题标题】:How to get checkbox value from database using jquery in mvc如何在 mvc 中使用 jquery 从数据库中获取复选框值
【发布时间】:2018-10-01 12:15:17
【问题描述】:

值显示在 Is Canceled = true 但复选框未选中。 任何人都可以告诉如何在 true 时编写代码,然后复选框选中,如果 false 则未选中。此代码无效。

function POGetby(PO_ID) {

            $.ajax({
                url: "/Home/POMain_Select",
                type: "GET",
                contentType: "application/json;charset=UTF-8",
                data: { 'PO_ID': PO_ID },
                dataType: "json",
                success: function (result) {

                    if (!$("#IsUCancelled").is(":checked")) {
                        $('#IsUCancelled').val(result.IsCancelled);
                    }

                    $('#UpdateModel').modal('show');
                    $('#UpdatePO').show();
                },
                error: function (errormessage) {
                    alert(errormessage.responseText);
                }
            });
            return false;
        }

【问题讨论】:

标签: jquery json model-view-controller


【解决方案1】:
$('#IsUCancelled').prop('checked', result.IsCancelled);

【讨论】:

  • @HelloWorld 你的条件是真的吗?
  • @HelloWorld if (!$("#IsUCancelled").is(":checked")) 这个语句是多余的
  • $('#IsUCancelled').attr('checked', result.IsCancelled);这个工作正常。
  • @HelloWorld .attr 已弃用。最好不要使用。
猜你喜欢
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 2017-08-13
  • 1970-01-01
  • 2016-03-04
  • 2022-07-28
相关资源
最近更新 更多