找回密码
 立即注册

QQ登录

只需一步,快速开始

火水

高级会员

90

主题

234

帖子

1034

积分

高级会员

积分
1034

微信认证勋章

火水
高级会员   /  发表于:2018-12-27 15:30  /   查看:2562  /  回复:1
多选框勾选东西同时勾选其他项,其他项未填可以保存,如何解决这个问题
方法一:在保存按钮加JavaScript:
function checkEmptyOtherText() {
    var checkboxes = $('input[othercheck="otherCheck"]');
    for(var i = 0; i < checkboxes.length; i++) {
        var checkbox = checkboxes[i];
        if (checkbox.checked) {
            var textInput = $(checkbox).parent().siblings(':last');
            if (textInput.val() == '') {
                alert('有空值');
            }
        }
    }
}

方法二:在页面加载加JavaScript:
$('input[othertext="otherText"]')
  .focusout(function(event) {
     var target = event.target;
     if (typeof (target.value) === 'undefined' || target.value === '') {
        
        var labels = $(target).siblings('label');
        var otherCheck = labels[labels.length - 1];
        var isChekced = $(otherCheck).find('input')[0].checked;
        if (isChekced) {
            alert('该值不能为空');
        }
     }
  });



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

评分

参与人数 1金币 +66 收起 理由
Simon.hu + 66 赞一个!

查看全部评分

1 个回复

倒序浏览
Simon.hu讲师达人认证 悬赏达人认证 活字格认证
超级版主   /  发表于:2018-12-27 15:31:40
沙发
感谢分享!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部