下記の様にチェックが入ったら入力欄が有効化するものがあるのですが、リロード時にチェック状態をみて維持しようとしても、ChromeやIE・edgeではチェックや値がクリアされてしまいます。
firefoxのみリロードしてもチェックや値がクリアされず想定どおりの動きをします。
ChromeやIE・edgeに対応するには、cookieかlocalstorage、sessionstorageを使わなければ対応できないのでしょうか?
ご存知の方がおられましたら、ご回答よろしくお願いします。
html
1<p><input type="checkbox" name="edit_flg" value="" class="checkbox" id="change" />入力する</p> 2<table id="change_list"> 3<tr> 4<th>入力1</th> 5<td><input type="text" value="" /></td> 6</tr> 7<tr> 8<th>入力2</th> 9<td><input type="radio" name="test" value="" checked="checked" />A <input type="radio" name="test" value="" />B</td> 10</tr> 11<tr> 12<th>入力3</th> 13<td><input type="checkbox" name="test" value="" checked="checked" />A <input type="checkbox" name="test" value="" />B</td> 14</tr> 15<tr> 16<th>入力4</th> 17<td><textarea value="" style="width:250px"></textarea></td> 18</tr> 19</table>
javascript
1$(function(){ 2 $("input#change").each(function(){ 3 var chk = $(this).prop('checked'); 4 if(chk == true){ 5 $("table#change_list input,table#change_list textarea").removeAttr("disabled"); 6 }else{ 7 $("table#change_list input,table#change_list textarea").prop('disabled', true); 8 } 9 return true; 10 }); 11 $("input#change").click(function(){ 12 var chk = $(this).prop('checked'); 13 if(chk == true){ 14 $("table#change_list input,table#change_list textarea").removeAttr("disabled"); 15 }else{ 16 $("table#change_list input,table#change_list textarea").prop('disabled', true); 17 } 18 return true; 19 }); 20});
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。