2012-05-18 12 views

risposta

12

Non è possibile impostare .innerHTML direttamente dall'oggetto jQuery. Devi invece impostare $.html().

// jQuery doesn't have an innerHTML property, so this is wrong 
$("#dialog").innerHTML = "This is the wrong way"; 

// jQuery has an html() method that sets the html within your dialog 
$("#dialog").html("And this is the correct way"); 

Tenere presente che quando hai a che fare con jQuery, hai a che fare con un oggetto, e non un elemento. Attributi come .innerHTML esistono su elementi all'interno del DOM, ma non all'interno dell'oggetto jQuery. jQuery fornisce metodi come $.html() in modo da non dover mai toccare .innerHTML.

1

questo è il modo di fare:

in JavaScript:

document.getElementById('dialog').innerHTML = 'something'; 

in jQuery:

$("#dialog").html('something'); 
Problemi correlati