退房this live jsfiddle
HTML:
<input type="checkbox" class="check1">Show checkbox</input>
<input type="hidden" class="hidden1" value="Some Value" />
<input type="text" class="text1" style="display:none" />
JQUER Y:
$(".check1").click(function() {
if ($('.check1').is(':checked')) {
$(".text1").val($(".hidden1").val());
$(".text1").show();
} else {
$(".text1").val("");
$(".text1").hide();
}
});
根據您發佈的代碼,這是你在找什麼:
$('.options input[type='checkbox']').click(function() {
if ($('.options input[type='checkbox']').is(':checked')) {
$('form').html("<input type='text'>");
} else {
$('form').html("<input type='hidden'>");
}
});
爲什麼你要做到這一點,我沒有用,雖然。你只是想顯示和隱藏文本框?在這種情況下,你可以這樣寫:
$('.options input[type='checkbox']').click(function() {
$('input[type='text']').toggle();
});
http://www.w3schools.com/jquery/jquery_dom_set.asp 檢查出的「設置屬性」 – 2013-03-23 23:49:54
請張貼在jsFiddle.net – j08691 2013-03-23 23:50:23
你已經嘗試了代碼,並儘可能的例子的例子中,沒有problemo! :) – 2013-03-23 23:50:56