JQuery 1.7 $ (this) .attr (‘type’) pour select donne undefined au lieu de “select-one” – Pourquoi?

J’ai un exemple que j’ai fait avec JQuery 1.4

voici le html:

   Formularseite       
Demo1 JQuery

Bitte wählen: Eintrag anderer Eintrag weiterer Eintrag

voici le js:

 // Add RegExp Filter // From: http://james.padolsey.com/javascript/regex-selector-for-jquery/ $.expr[':'].regex = function(elem, index, match) { var matchParams = match[3].split(','), validLabels = /^(data|css):/, attr = { method: matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr', property: matchParams.shift().replace(validLabels,'') }, regexFlags = 'ig', regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags); return regex.test(jQuery(elem)[attr.method](attr.property)); } $(document).ready(function() { $('body').addClass('js'); // Toggeling groups $(".groupsortinggger").change( function() { var toCheck = ":not(:checked)"; if ($(this).hasClass('inverse')) toCheck = ":checked"; var hideGroup = "."+this.id; // for radio buttons alert (" "+$(this).attr('type')+' '+this.id); if ($(this).attr('type') == "radio") { var hideGroupParent=hideGroup.substr(0,hideGroup.length-1); try { $("div:regex(class, .*"+hideGroupParent+".*)").hide(0); } catch (err) {} if ($("#" + this.id).is(":checked")) $(hideGroup).show(0); } // for select lists else if ($(this).attr('type') == "select-one") { var hideGroupParent=this.id; hideGroup = '.'+$('#' + this.id + ' :selected').attr('id'); try { $("div:regex(class, .*"+hideGroupParent+".*)").hide(0); } catch (err) {} $(hideGroup).show(0); } else // for checkboxes { if ($("#" + this.id).is(toCheck)) try { $(hideGroup).hide(100); } catch (err) {} else $(hideGroup).show(100); } }); $(".groupsortinggger").change(); }); 

Le problème avec JQuery 1.7 est que

 alert (" "+$(this).attr('type')+' '+this.id); 

renvoie “indéfini” pour la sélection au lieu de “select-one” comme ce fut le cas avec JQuery 1.4. Est-ce un bug ou existe-t-il un autre moyen de détecter l’élément select?

sur le site jQuery vous trouvez cette information

A partir de jQuery 1.6, la méthode .attr () renvoie non défini pour les atsortingbuts non définis. De plus, .attr () ne doit pas être utilisé sur des objects simples, des tableaux, la fenêtre ou le document. Pour récupérer et modifier les propriétés DOM, utilisez la méthode .prop ().

alors utilisez prop('type')

Eh bien, techniquement, la select n’a pas d’atsortingbut de type (et s’il en avait une, ce serait une erreur HTML), ce n’est donc pas un bogue, mais une fonctionnalité de jQuery 1.7. Si vous voulez isoler la select utilisez simplement l’un de ceux-ci:

 $(this).is('select') === true $(this).filter('select').length > 0