JQuery working with title and src attributes

After the script to be checked, I will receive the src attribute for input, then I will look at all the other checkboxes and radio buttons .eachand delete the checked attribute of any inputs, the title attribute 'RQlevel' + this.src. Hope this is clear enough.

Here is my attempt, however this is not true.

function levels() {
   if ($(this).is(':not(:checked)').each(function()) {
        if($(':input').attr('title', 'RQlevel' + this.src) {
        $(':input').removeAttr('checked');
        });
   });    
} 

Working example at http://jsfiddle.net/V8FeW/

0
source share
2 answers

I think you have your links to thisconfused. If I understand your question correctly, this should do what you want:

function levels() {
  var $this = $(this); // Cache a reference to the element that was clicked
  if ($this.is(':not(:checked)') { // Determine if the clicked element is checked
    $(':input').each(function() { // Loop through every input element
      // Here, 'this' is the current element in the loop and
      // '$this' is the originally clicked element.
      if (this.title === ('RQLevel' + $this.attr('src'))) {
        $(this).removeAttr('checked');
      }
    });
  }
}

Update:

, src . src , URL. "2" "http://example.com/2". , . . jsfiddle .

, onclick jQuery . bind(). JavaScript:

$(function() {
    $(':input').bind('click', function() {
        var src = $(this).data('src');

        if (!this.checked) {
            $('input:checked').each(function(){
                if (this.title === ('RQlevel' + src)) {
                    this.checked = false;
                }
            });
        }
    }); 
});
+1

:

function levels() {
    if (!this.checked) {
        var src = this.src;
        $('input:checkbox, input:radio').each(function(){
            if (this.title === 'RQlevel' + src) {
                this.checked = false;
            }
        });
    }
}

, :

$('#yourCheckbox').click(levels);

, , RQlevel, src clicked. , , src each this.src, src .

0

Source: https://habr.com/ru/post/1788209/


All Articles