php - 基于单选按钮启用/禁用提交按钮

标签 php javascript jquery

我的表单布局如下:

<form action="join-head-2-head.php" method="POST" enctype="application/x-www-form-urlencoded">
    <table border="0" cellspacing="4" cellpadding="4">
        <tr>
          <td colspan="2"><input name="player1rules" type="radio" id="tandcy" value="y" />
          <label for="tandcy">I  Have Reviewed The Rules And The Terms &amp; Conditions And Agree To Abide By Them</label></td>
      </tr>
        <tr>
            <td colspan="2"><input name="player1rules" type="radio" id="tandcn" value="n" checked="checked" /><label for="tandcn">I Do Not Agree To The Terms And Condtions And/Or Have Not Read The Rules</label></td>
        </tr>
        <tr>
            <td width="100"><input name="player1" type="hidden" value="<? $session->username; ?>" /></td>
            <td><input type="submit" name="join" id="join" value="Take Available Slot" /></td>
        </tr>
    </table>
</form>

我希望做的是如果选择 id="tandcn"则禁用提交按钮,并在选择 id="tandcy"时启用它。有没有一种简单的方法可以使用 JavaScript 来做到这一点?

最佳答案

示例http://jsfiddle.net/sWLDf/

$(function () {
    var $join = $("input[name=join]");
    var processJoin = function (element) {
        if(element.id == "tandcn") {
            $join.attr("disabled", "disabled");
        }
        else {
            $join.removeAttr("disabled")
        }
    };

    $(":radio[name=player1rules]").click(function () {
        processJoin(this);
    }).filter(":checked").each(function () {
        processJoin(this);
    });
});

关于php - 基于单选按钮启用/禁用提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818415/

相关文章:

php - 替代 php silex 模板

Javascript:绑定(bind)到函数的右侧?

javascript - $(...).tagsinput 不是函数

php - 使用 php 和 mysql 将数据插入表的正确方法?

php - 如何检查数据库中已存在的值?

PHP比较两个值?

javascript - 这种声明的目的是什么?

javascript - 单击删除按钮时突出显示评论并删除类

jquery - 强制 jQuery 将 div 与两个类标签相匹配,而不仅仅是一个

jquery - 使用CSS在子菜单前添加三 Angular 形