微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 仅在填写所有字段时启用提交按钮

在我的表单中,我想只在选择了所有字段(和单选按钮列表)时启用表单.

到目前为止,当标题字段包含以下内容时,我已成功启用提交按钮:

onkeyup="if(this.textLength != 0) {subnewtopic.disabled = false} else {subnewtopic.disabled = true}"

我的目标是只在所有内容都填满后启用提交按钮.我该怎么做呢?

这是我的完整代码,工作jsfiddle

<form action="" method="post" id="subnewtopicform" />

                Title:
                <input type="text" name="title" onkeyup="if(this.textLength != 0) {subnewtopic.disabled = false} else {subnewtopic.disabled = true}">

<br/>

                Description:
                <textarea name="description"></textarea> 

<br/>
                Category:
<ul class="list:category categorychecklist form-no-clear" id="categorychecklist">

<li id="category-19"><label class="selectit"><input type="radio" id="in-category-19" name="category" value="19"> Animation</label></li>

<li id="category-20"><label class="selectit"><input type="radio" id="in-category-20" name="category" value="20"> Anime</label></li>

    </ul>

                <input type="submit" value="Submit Topic" class="button-primary" name="subnewtopic" id="subnewtopic" disabled="disabled" /> 

            </form>

解决方法

这是你的小提琴. http://jsfiddle.net/soyn0xag/6/
$("input[type='text'],textarea").on("keyup",function(){
    if($(this).val() != "" && $("textarea").val() != "" && $("input[name='category']").is(":checked") == true){
        $("input[type='submit']").removeAttr("disabled");
    } else {
        $("input[type='submit']").attr("disabled","disabled");
    }
});

$("input[name='category']").on("change","disabled");
    }
});

原文地址:https://www.jb51.cc/jquery/180811.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐