以下是来自smarty模板的代码片段。
<input type="radio" name="newsletter_call_to_action_status" value="1" checked='checked' onclick="select_option(this.value);" {if $data.newsletter_call_to_action_status=='1' } checked {/if}>Yes
<input type="radio" name="newsletter_call_to_action_status" value="0" onclick="select_option(this.value);" {if $data.newsletter_call_to_action_status=='0' } checked {/if}>No
<tr id="action_link_no" {if $data.newsletter_call_to_action_status=='1' }style="display:;" {else}style="display:none;" {/if}>
<td colspan="2"> </td>
</tr>
<tr class="action_link_yes" height="30">
<td align="right" width="300">
<label><b>{'Enter call to action text'|signal_on_error:$error_msg:'newsletter_call_to_action_text'}</b> <strong style="color:red">*</strong>
</label>
</td>
<td>
<input type="text" name="newsletter_call_to_action_text" id="newsletter_call_to_action_text" value="{$data.newsletter_call_to_action_text}" maxlength="50" class="inputfield">
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr class="action_link_yes" height="30">
<td align="right" width="300">
<label><b>{'Enter call to action link'|signal_on_error:$error_msg:' newsletter_call_to_action_link'}</b> <strong style="color:red">*</strong>
</label>
</td>
<td>
<input type="text" name="newsletter_call_to_action_link" id="newsletter_call_to_action_link" value="{$data.newsletter_call_to_action_link}" class="inputfield">
</td>
</tr>
现在,在表单加载时,如果newsletter_call_to_action_status == 1
,它应显示tr
class=action_link_yes
,并在值为tr
时隐藏class=action_link_no
0
。
我怎样才能做到这一点?
答案 0 :(得分:1)
<input type="radio" value="1" checked="checked">YES</input>
<input type="radio" value="0">NO</input>
<table class="tbl">
<tr class="action-yes">
<td>Here is stuff to show on yes</td>
</tr>
<tr class="action-no">
<td>stuf to show on no</td>
</tr>
</table>
$(document).ready(function () {
var status = $('input:radio:checked').val();
if (status == 1) {
$('table tr.action-yes').show();
$('table tr.action-no').hide();
} else {
$('table tr.action-yes').hide();
$('table tr.action-no').show();
}
});
答案 1 :(得分:0)
$('#form').load(function(){
if(newsletter_call_to_action_status == 1) {
$('.class=action_link_yes').show();
$('.class=action_link_no').hide();
}
else {
$('.class=action_link_yes').hide();
$('.class=action_link_no').show();
}
});
答案 2 :(得分:0)
试试这个:
(文档)$。就绪(函数(){
$(".radio").change(function(){
if($(this).val() == '1')
{
$(".action_link_no").hide();
$(".action_link_yes").show();
}
else if($(this).val() == '0')
{
$(".action_link_yes").hide();
$(".action_link_no").show();
}
});
});
这里.radio是单选按钮类