Skip to content

Instantly share code, notes, and snippets.

@shiranuik
Created August 25, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiranuik/f9e20b5ec176aa6a8894 to your computer and use it in GitHub Desktop.
Save shiranuik/f9e20b5ec176aa6a8894 to your computer and use it in GitHub Desktop.
jQueryでブラウザ戻るボタンによるフォームずれ対応
// option[selected]によって「ソース上の」選択状態を取得。
var tmpSelect = $('select[name="selectName"] option[selected]').val();
// option:selected (見かけ上の選択状態)を削除。
$('select[name="selectName"] option:selected').removeAttr('selected');
// 改めて選択を設定しなおす。
$('select[name="selectName"]').val(tmpSelect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment