我创建了一个代码,通过单击另一个RADIO单击RADIO和其他信息来显示信息。Javascript隐藏/显示数据作为输入收音机
正常工作,但是当我更新页面时,即使CHECKED也不显示任何信息。然后,我必须再次单击已经检查过的RADIO信息才能出现。
任何人都知道如何解决?
按照下面的代码:
<script>
// COLOR BG OR IMG BG
$(document).ready(function(){
$("input[name$='userBgOrImg']").click(function() {
var test = $(this).val();
$("div.desc").hide();
$("#"+test).show();
});
});
</script>
<style type="text/css">
.desc { display: none; }
</style>
<div><label><input type="radio" name="userBgOrImg" value="1" <?php $id = $res_select["id"]; if ($userBgOrImg == 1) { echo "checked=\"checked\"";} else { echo "";}?>>Cor de Fundo</label></div>
<div><label><input type="radio" name="userBgOrImg" value="2" <?php $id = $res_select["id"]; if ($userBgOrImg == 2) { echo "checked=\"checked\"";} else { echo "";}?>>Imagem de Fundo</label></div>
<div> <br /> <br /> </div>
<div id="1" class="desc">
<label for="userBgBody">Cor do fundo do Site</label>
<input type="text" class="form-control bscp span12" value="<?php $id = $res_select["id"]; echo $userBgBody; ?>" id="userBgBody" name="userBgBody">
<hr />
</div>
<div id="2" class="desc">
<label for="userImgBody">Imagem de fundo do site</label>
<input type="text" class="span12" name="userImgBody" id="userImgBody" placeholder="Imagem do fundo do site" value="<?php $id = $res_select["id"]; echo $userImgBody; ?>" />
<hr />
<label for="userImgBodyRepeat">Repetir imagem de fundo</label>
<span> <input type="radio" name="userImgBodyRepeat" value="repeat"> Sim</span> <span> <input type="radio" name="userImgBodyRepeat" value="no-repeat" selected="selected"> Não
<hr />
</div>
预先感谢您的帮助。
工作在这个小提琴检查out..http罚款://jsbin.com/OGoVoJI/6/edit – codebreaker
@Vitor de Sousa,你的代码不工作,因为你已经为单选按钮分配了一个单击,通常一个检查事件被附加到一个单选按钮。尝试为单选按钮分配一个检查事件并进行测试。希望工程。 –