12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【jQuery】IE8でinputのchangeが効かないときの対処法

Last updated at Posted at 2014-07-12

IEは本当にやっかいだ。
以下の方法で解決できたので、よかった。

HTML

index.html
<ul class="radio">
  <li><label><input type="radio" name="bloodtype" value="A" checked />A</label></li>
  <li><label><input type="radio" name="bloodtype" value="B" />B</label></li>
  <li><label><input type="radio" name="bloodtype" value="O" />O</label></li>
  <li><label><input type="radio" name="bloodtype" value="AB" />AB</label></li>
</ul>

jQuery

jquery.js
$(".radio").change(function(){
	$(".radio label").removeClass("radio-checked");
	$(this).parent("label").addClass("radio-checked");
});

//IE8用
$(".radio input").closest("label").on("click", function(e){
	var input = $(this).find("input");
	if(! input.prop("checked")){
	  input.prop("checked", true).trigger("change");
	}
});
12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?