Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Выделить radio, удалив все остальные. (https://javascript.ru/forum/misc/51002-vydelit-radio-udaliv-vse-ostalnye.html)

light 20.10.2014 17:03

Выделить radio, удалив все остальные.
 
По отдельности все работает, но вместе работать не хочет.
<script> 
$(function() { 
 	$("#test").click(function(){  
		$(".radioId").removeAttr("checked");
		$("#radioId"+$(this).attr('data-id')).attr('checked', 'checked');		 
	});   
});
</script>


<input id="radioId318" class="radioId" type="radio" value="318" name="radioId">
<input id="radioId319" class="radioId" type="radio" value="319" name="radioId">
<input id="radioId320" class="radioId" type="radio" value="320" name="radioId">
<input type="submit" id="test" data-id="319" />

рони 20.10.2014 17:11

light,
:-?
<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <script>
$(function() {
 	$("#test").click(function(){
		$(".radioId").prop("checked", false);
		$("#radioId"+$(this).data('id')).prop("checked", true);
	});
});
</script>

</head>

<body>
<input id="radioId318" class="radioId" type="radio" value="318" name="radioId">
<input id="radioId319" class="radioId" type="radio" value="319" name="radioId">
<input id="radioId320" class="radioId" type="radio" value="320" name="radioId">
<input type="submit" id="test" data-id="319" />
</body>

</html>

light 20.10.2014 17:28

рони,
Спасибо) очень помогли.


Часовой пояс GMT +3, время: 20:09.