2016-11-30 19 views
5
var selector = '#Id-value_' + index; 
var exist = $(selector).exists(); 

Bu kod parçası için hata alıyorum.
Belgem hazır fonksiyon

$(document).ready(function() { 

}); 

cevap

6

jQuery hiçbir exists() işlevi yoktur olduğunu. Ama çabuk birini yazabilirsiniz: o $(selector).length kullanarak varsa

//add a new function to jQuery 
jQuery.fn.exists = function(){return this.length>0;} 

//now let's test it 
if ($(selector).exists()) { 
    // Do something 
} 
3

@ K48 cevap dayanarak, aynı zamanda doğrudan kontrol edebilir.

var selector = '#Id-value_' + index; 
if ($(selector).length) { 
    // Do something 
} 
İlgili konular