我創建了一個代碼,通過單擊另一個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,你的代碼不工作,因爲你已經爲單選按鈕分配了一個單擊,通常一個檢查事件被附加到一個單選按鈕。嘗試爲單選按鈕分配一個檢查事件並進行測試。希望工程。 –