【问题标题】:Enable/Disable Submit Button with Javascript in combination with Primefaces and Twitter bootstrap [duplicate]使用 Javascript 结合 Primefaces 和 Twitter 引导程序启用/禁用提交按钮 [重复]
【发布时间】:2013-04-17 18:01:33
【问题描述】:

如果复选框未选中/选中,我想禁用/启用提交按钮,但按钮的状态没有改变。

我在这里找到了解决方案:How do i disable a submit button when checkbox is uncheck?

复选框:

<h:selectBooleanCheckbox id="termsOfUseCheckbox" name="Sign Up" class="input-xlarge"/>

提交按钮:

<p:commandButton type="submit" id="submitButton" action="#{genPlaceUserService.persist()}" value="Sign up" styleClass="btn btn-primary btn-large" disabled="true"></p:commandButton>

Javascript:

<script type='text/javascript'>
$('#termsOfUseCheckbox').click(function(){

    if($(this).attr('checked') == true){

        $('#submitButton').removeAttr('disabled');
    }
    else {
        $('#submitButton').attr("disabled","true"); 
    }
});

我知道 primefaces 需要禁用状态 (disable=true),这应该由以下人员完成:

$('#submitButton').attr("disabled","true");

感谢您的帮助, 亲切的问候!

【问题讨论】:

    标签: javascript html jsf twitter-bootstrap primefaces


    【解决方案1】:

    你可以使用这个 -> $(this).is(':checked') 代替 $(this).attr('checked'),这是一个 jsfiddle -> http://jsfiddle.net/AfUGd/3/

    修改了小提琴

    【讨论】:

    • 感谢您的帮助!但是按钮仍然没有对复选框的状态做出反应..我知道xhtml需要禁用=“disbled”,但我认为primefaces需要禁用=“true”。我尝试了两种变体,但都不起作用。
    【解决方案2】:

    其实你需要做的不是将disabled设置为true,而是像这样设置disabled为disable

    $('#submitButton').attr("disabled","disabled");
    

    【讨论】:

      猜你喜欢
      • 2021-05-23
      • 2019-03-19
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 2020-06-21
      相关资源
      最近更新 更多