如果选中单选按钮(默认情况下或单击)并且.active包含此文本,则隐藏按钮

时间:2015-11-09 14:53:43

标签: jquery

如果选中包含“No,I not not”值的单选按钮并且.active包含文本“Commitment Statement”,我想隐藏Submit按钮。请注意,默认情况下会选中此单选按钮,因此onclick功能将不起作用。此外,在加载时隐藏按钮不起作用,因为如果您选择是,则您将进入仍在同一页面上的进程的后续步骤,这将导致在下一步隐藏“提交”按钮。

请参阅jsfiddle以获取完整代码:http://jsfiddle.net/jelane20/w6z6gk3b/1/

<span class="testSequenceMapCurrentStepItem">Commitment Statement</span>

<table cellspacing="0" cellpadding="0" style="border-collapse:collapse;" class="testFormDisplayRadioButtonList" id="PC6728_formWizard_formWizard_5aa9a035_c1e7_4738_9686_144f66cfce5d">
    <tbody><tr>
        <td><input type="radio" onclick=" test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), 'f062efd8-a797-4a23-845d-ecec13e86709'); test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), '6d436f03-3afe-4bf8-998b-979c9cd0a3fd'); test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), '7085eb80-4639-4279-952e-65f8041ec5ab');" value="I understand and agree to the rules of the Turning Points Essay Contest (you must agree to proceed with registration)" name="PC6728$formWizard$formWizard$5aa9a035_c1e7_4738_9686_144f66cfce5d" id="PC6728_formWizard_formWizard_5aa9a035_c1e7_4738_9686_144f66cfce5d_0"><label for="PC6728_formWizard_formWizard_5aa9a035_c1e7_4738_9686_144f66cfce5d_0">I understand and agree to the rules of the Turning Points Essay Contest (you must agree to proceed with registration)</label></td>
    </tr><tr>
        <td><input type="radio" onclick=" test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), 'f062efd8-a797-4a23-845d-ecec13e86709'); test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), '6d436f03-3afe-4bf8-998b-979c9cd0a3fd'); test.FormWizard.triggerHideStepRule((($(this).is(':checked') &amp;&amp; $(this).val() === 'No, I do not agree with the rules of the Turning Points Essay Contest')), '7085eb80-4639-4279-952e-65f8041ec5ab');" checked="checked" value="No, I do not agree with the rules of the Turning Points Essay Contest" name="PC6728$formWizard$formWizard$5aa9a035_c1e7_4738_9686_144f66cfce5d" id="PC6728_formWizard_formWizard_5aa9a035_c1e7_4738_9686_144f66cfce5d_1"><label for="PC6728_formWizard_formWizard_5aa9a035_c1e7_4738_9686_144f66cfce5d_1">No, I do not agree with the rules of the Turning Points Essay Contest</label></td>
    </tr>
</tbody></table>

<input type="button" class="testSequenceMapNavigationButton testFormDisplaySequenceMapNavigationButton testSequenceMapNavigationNextButton testFormDisplaySequenceMapNavigationNextButton" id="PC6728_formWizard_formWizard_nextWizardButton" onclick="(function(btn){var bDisableMe=true;if(typeof(Page_ClientValidate)=='function'){bDisableMe=Page_ClientValidate('CustomForm');}if (bDisableMe) {__doPostBack('PC6728$formWizard$formWizard$nextWizardButton','');btn.disabled=bDisableMe;}})(this);return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;PC6728$formWizard$formWizard$nextWizardButton&quot;, &quot;&quot;, true, &quot;CustomForm&quot;, &quot;&quot;, false, true))" value="Next" name="PC6728$formWizard$formWizard$nextWizardButton">

1 个答案:

答案 0 :(得分:0)

我不会在您的HTML或小提琴中看到&#34; .active&#34;元素是。但我认为这样的事情会起作用。

$(function(){
    setSubmit();

    $('.testFormDisplayRadioButtonList input:radio').click(function(){
        setSubmit();
    });
});


// Create a standalone function to disable and enable the button 
// so it can be called on load and on radio button click
function setSubmit(){
    var text = $('.testFormDisplayRadioButtonList input:radio:checked').val();
    var activeText = $('.active').text();
    if(text.indexOf('No, I do not') === 0 && activeText.indexOf('Commitment Statement') > -1){
        $('input:button').attr('disabled', 'disabled');
    }else{
        $('input:button').removeAttr('disabled');
    }
}