Created
June 24, 2019 10:09
-
-
Save todays-mitsui/07ada597185fb932c60ab6a858cbe708 to your computer and use it in GitHub Desktop.
ラジオボタンをクリックで OFF 可能にする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ラジオボタンをクリックで OFF 可能にする | |
*/ | |
jQuery(function($) { | |
var names = $('input[type=radio]').map(function() { | |
return $(this).attr('name'); | |
}); | |
names = _.uniq(names); | |
var selected_vals = Object.create(null); | |
for (var i = 0, len = names.length; i < len; i++) { | |
var name = names[i]; | |
selected_vals[name] = null; | |
} | |
$('input[type=radio]').each(function() { | |
$(this).on('click', function(e) { | |
var $radio = $(this); | |
var name = $radio.attr('name'); | |
if ($radio.val() == selected_vals[name]) { | |
$radio.prop('checked', false); | |
selected_vals[name] = null; | |
} else { | |
selected_vals[name] = $radio.val(); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment