我想检查 radio 的值是否为某个值,如果是,则需要回显文本行。
我将此代码用于单选按钮:
<li>
<label for="recommend_field"><?php echo $this->__('Would you recommend this product to a friend?') ?></label>
<div class="input-box">
<?php foreach ( $this->getOptions() as $option ): ?>
<label>
<input type="radio" class="radio" name="radio-group" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' checked="checked"' ?>><?php echo __($option['label']) ?></input>
</label>
<?php endforeach ?>
</div>
</li>
我目前用这一行回显单选按钮的整个值:
<?php echo $this->__('Would you recommend this product to a friend?') ?> <?php echo $this->getAnswer() ?>
单选按钮的值为
1.是的
2. 否
我想检查值是否为 Yes,如果是,则回显“Value is Yes”。
我怎样才能实现这一目标?
最佳答案
<li>
<label for="recommend_field"><?php echo $this->__('Would you recommend this product to a friend?') ?><span id='ans'></span></label>
<div class="input-box">
<?php foreach ( $this->getOptions() as $option ): ?>
<label>
<input type="radio" class="radio" name="radio-group" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' checked="checked"' ?>><?php echo __($option['label']) ?></input>
</label>
<?php endforeach ?>
</div>
</li>
<script>
$(document).ready(function(){
$('input:radio[name=radio-group]:checked').change(function () {
if (this.value == 'Yes') {
$('#ans').html("Value is Yes");
}
else if (this.value == 'No') {
$('#ans').html("Value is No");
}
});
</script>
关于javascript - 如果单选按钮的答案是 echo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30482747/