【问题标题】:How can i Validate when Value of one row is similar with one another我如何验证一行的值何时彼此相似
【发布时间】:2013-07-19 02:32:10
【问题描述】:

我想在保存时验证 Contact Type 值何时具有 True Primary,以便只有一个 Contact Type 值是 Primary,

我如何使用 jquery 或 Javascript 处理它:(

谢谢

var row = obj.closest("tr").find("input[name=workerId]").val();
            var contactValue = obj.closest("tr").find("input[name=contactValue]").val();
            var contactType = obj.closest("tr").find("input[name=contactType]").val();
            var isPrimary = obj.closest("tr").find("input[name=isPrimary]").val();
            // get the value of  the checkbox in edit modal window
            if (isPrimary === 'true') {
                $('#chkEditWorkerIsPrimary').attr('checked', 'checked');
            } else {
                $('#chkEditWorkerIsPrimary').removeAttr('checked');
            }

【问题讨论】:

    标签: c# javascript jquery asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    您可以计算 isPrimary 列具有真值的行数并检查它是否匹配 1。否则显示警告或错误消息

    var isPrimaryCount = $('#testTable').find('tr input[name=isPrimary][value=true]').length
    if (isPrimaryCount < 1 || isPrimaryCount > 1) {
        alert('message to user')
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      相关资源
      最近更新 更多