Perché sono elementi nulli in jquery, esistono ancora con document.getElementById ()

voti
1

I sto cercando di allegato alcune jQuery per caselle di controllo in un GridView, utilizzando document.ready:

  $(document).ready(function()
  { 
       var chkBox= document.getElementById(gvTimeSheet_ctl01_chkAll1);
       //I can alert chkBox.id, element exists

       var name = $(input[name='gvTimeSheet$ctl01$chkAll1']);
       //Here, when I alert the id, I get a null

       var ID = $(#gvTimeSheet_ctl01_chkAll1);
      //Here, when I alert the id, I get a null

       var withClass = $(.chkAll1Class);
       //Here, when I alert the id, I get a null

       var withClass2 = $(.Bill1);
       //Here, when I alert the id, I get a null

       //This line causes the browswer to crash and gives me the following error
       //Microsoft JScript runtime error: 'null' is null or not an object
       $(#gvTimeSheet_ctl01_chkAll1).click(function()           
       {
           var checked_status = this.checked;
           $(input[class=Bill1]).each(function()
           {
           this.checked = checked_status;
           });

       });

    });*/

Allora, perché sono i tentativi di trovare un oggetto nullo in jQuery, esistono ancora in javascript regolare entro lo stesso metodo? Che cosa mi manca qui. Ho i file jQuery js portati in un tag script direttamente sopra questo metodo. Io proprio non riesco a trovare tutti gli oggetti in questa pagina con jQuery. In altre pagine, posso.

È pubblicato 11/08/2009 alle 19:52
fonte dall'utente
In altre lingue...                            


4 risposte

voti
2

Gli oggetti che derivano da un selettore jQuery sono in realtà wrapper attorno a un oggetto DOM, in modo da non accedono lo stesso come un oggetto DOM.

Se si sta avvisando solo "name.id", dal tuo primo esempio di cui sopra, non ci sarà alcun tale proprietà sulla confezione jQuery. Prova avvisando l'ID come segue:

alert(name.attr("id"));
Risposto il 11/08/2009 a 20:00
fonte dall'utente

voti
1
 var ID = $("#gvTimeSheet_ctl01_chkAll1");

Questo restituisce un oggetto jQuery, non un ID. ID.id sarebbe anche essere indefinito. Per ottenere l'ID, è necessario:

var ID = $("#gvTimeSheet_ctl01_chkAll1").attr("id");
Risposto il 11/08/2009 a 20:02
fonte dall'utente

voti
0

Fa la pagina che si sta aggiungendo questo codice per includere già la libreria Prototype JavaScript?

metodo del "$" di jQuery non restituisce un valore nullo, quindi questo non dovrebbe essere un problema:

// This line causes the browswer to crash and gives me the following error
// Microsoft JScript runtime error: 'null' is null or not an object
$("#gvTimeSheet_ctl01_chkAll1").click(function() { .... });

Tutti i commenti sul bisogno di usare .attr('id')ancora in piedi (anche se io preferisco $('#whatever')[0].idme stesso.)

Risposto il 11/08/2009 a 20:15
fonte dall'utente

voti
2
var val = $("input:radio[name$='rdoselect']:checked").val();           
if (val == 1) {            
    $('[id$=divDate]').attr('disabled', true);                 
}else {             
    $('[id$=divDate]').attr('disabled', false);
}
Risposto il 26/02/2011 a 11:20
fonte dall'utente

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more