對不起,在原始文章中沒有更清楚。根據其他輸入字段有條件地顯示/隱藏未標註的標籤/輸入表單字段
我試圖隱藏頂部的兩個表單字段區域,當底部的複選框未選中時,不傳遞任何值,當他們被隱藏。這是wordpress的註冊表格,我不想修改html,這會使它更容易,因爲我可以接下divs中的標籤和輸入來隱藏。
這裏顯示的ID:
(頂部複選框) WS-插件 - s2member定製-REG-場通訊 (中間單選) WS-插件 - s2member定製-REG場-jobalerts (底部複選框ID) ws-plugin - s2member-custom-reg-field-opt-in
@Mosh建議以下是關閉,但只隱藏一個。
// Store the `p` node which contains the label.
var collapseParent = $('label[for="ws-plugin--s2member-custom-reg-field-jobalerts"]').parent();
// Store the `checkbox` that we want to "listen" to
var checkbox = $('[name="ws_plugin__s2member_custom_reg_field_opt_in"]');
// Attach the `change` event on the checkbox and trigger the event so it will fire on page load
checkbox.change(toggle).trigger('change');
// show/hide the `p` node depeneds if the checbox was checked or not
function toggle() {
collapseParent.toggle(checkbox.is(':checked'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
<label for="ws-plugin--s2member-custom-reg-field-newsletters">
<span style="display:none;">Do you wish to receive JETAAUK Newsletters? *</span>
</label>
<input type="checkbox" value="1" checked="checked" name="ws_plugin__s2member_custom_reg_field_newsletters" id="ws-plugin--s2member-custom-reg-field-newsletters" aria-required="true" tabindex="59" class="ws-plugin--s2member-custom-reg-field s2conditional1">
<label for="ws-plugin--s2member-custom-reg-field-newsletters" style="display:inline !important; margin:0 !important;">Do you wish to receive JETAAUK Newsletters?</label>
</p>
<p>
<label for="ws-plugin--s2member-custom-reg-field-jobalerts">
<span>Do you wish to receive job alerts (digest)? *</span>
</label>
<br>
<input type="radio" value="weekly" name="ws_plugin__s2member_custom_reg_field_jobalerts" id="ws-plugin--s2member-custom-reg-field-jobalerts---0" aria-required="true" tabindex="60" class="ws-plugin--s2member-custom-reg-field s2conditional2" style="color:#006699;">
<label for="ws-plugin--s2member-custom-reg-field-jobalerts-0" class="ws-plugin--s2member-custom-reg-field-op-l" style="display:inline !important; margin:0 !important;">weekly</label>
<input type="radio" value="daily" name="ws_plugin__s2member_custom_reg_field_jobalerts" id="ws-plugin--s2member-custom-reg-field-jobalerts---1" aria-required="true" tabindex="60" class="ws-plugin--s2member-custom-reg-field s2conditional2" style="color:#006699;">
<label for="ws-plugin--s2member-custom-reg-field-jobalerts-1" class="ws-plugin--s2member-custom-reg-field-op-l" style="display:inline !important; margin:0 !important;">daily</label>
<input type="radio" value="none" name="ws_plugin__s2member_custom_reg_field_jobalerts" id="ws-plugin--s2member-custom-reg-field-jobalerts---2" aria-required="true" tabindex="60" class="ws-plugin--s2member-custom-reg-field s2conditional2" style="color:#006699;">
<label for="ws-plugin--s2member-custom-reg-field-jobalerts-2" class="ws-plugin--s2member-custom-reg-field-op-l" style="display:inline !important; margin:0 !important;">none</label>
</p>
<p>
<label for="ws-plugin--s2member-custom-reg-field-opt-in">
<input type="checkbox" name="ws_plugin__s2member_custom_reg_field_opt_in" id="ws-plugin--s2member-custom-reg-field-opt-in" class="ws-plugin--s2member-custom-reg-field" value="1" checked="not" tabindex="70">
<span style="color:#be0026;"><strong>=> Yes, I wish to receive JETAAUK Newsletters via email <= </strong></span>
</label>
</p>
這是不是很清楚你想要隱藏/顯示。你能否澄清你想達到的工作流程? – Ant
Thanks @MrBearding我已重申與本指南更接近 –