<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function preview(){
temp = $(this).innerHTML;
testwin= open("", "testwin","status=no,menubar=yes,toolbar=no");
testwin.document.open();
testwin.document.write(temp);
testwin.document.close();
}
</script>
<table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
<tbody>
<tr>
<td onclick="preview()">dghfh</td>
</tr>
</tbody>
</table>
</html>
Passez un paramètre à la fonction preview() que vous avez déclarée, puis donnez la valeur du paramètre à la variable temp, et enfin changez l'appel en onclick=" preview(this.innerHTML)".
Test personnel, ça marche
Quant à $ (this).innerHTML Ceci est l'objet navigateur, pas l'objet jq
La fonction aperçu écrite en onclick sur l'élément pointe vers la fenêtre objet global, pas vers l'élément
$(this) est un objet jq, alors utilisez $(this).html()
$(this)[0].innerHTML;Par ici
Vous pouvez vous arrêter et jeter un œil à ce que $(this) vous avez écrit, il doit faire référence à la fenêtre, pas au td que vous voulez
$(this) est l'environnement contextuel enveloppé par jquery, et sa méthode spécifiée est requise pour obtenir le fragment statique interne.
Deux façons d'obtenir :
Écriture native : this.innerHTML
jquery : $(this).html()
jq+Native : $(this)[0].innerHTML ou this.get(0).html()
Voulez-vous natif ou jq