如何向<a>

时间:2018-04-03 19:35:25

标签: javascript css html5

I just want to add a radio button behavior(check only one item, change color when is checked, remove checked color when the other is checked.) to How can I do this in javascript? Here is my on click event.

$(document).on('click', '[data-change-option]', function(e) {
  e.preventDefault();
  console.log(e.target);
  var optionIndex = parseInt($(this).data('changeOption')), optionValue = $(this).data('changeValue');

  if(optionSelectors.optionExistInSelect(optionSelectors.selectors[optionIndex].element, optionValue)) {
    $(optionSelectors.selectors[optionIndex].element).val(optionValue).trigger('change');
  }
});

1 个答案:

答案 0 :(得分:0)

将所有类型的项重置为基色,而不是将单击的项更改为活动颜色:

$(document).on('click', '[data-change-option]', function() {
  $('[data-change-option]').css('color', '');
  
  $(this).css('color', 'red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#1" data-change-option="">Link 1</a>

<a href="#1" data-change-option="">Link 2</a>

<a href="#1" data-change-option="">Link 3</a>