javascript - $(this).innerHTML supprime l'indéfini, pourquoi
習慣沉默
習慣沉默 2017-05-19 10:44:11
0
8
749
<!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>
習慣沉默
習慣沉默

répondre à tous(8)
phpcn_u1582

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 :

$(this).html();
$(this).prop('innerHTML');
为情所困

Écriture native : this.innerHTML
jquery : $(this).html()
jq+Native : $(this)[0].innerHTML ou this.get(0).html()

習慣沉默

Voulez-vous natif ou jq

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal