javascript - $(this).innerHTML取出的是undefined,为什么
本文介绍了javascript - $(this).innerHTML取出的是undefined,为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!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>
解决方案
给你声明的函数 preview() 传一个参数,然后把参数的值给变量temp,,最后调用改为 onclick=" preview(this.innerHTML)".
亲测可行
至于 $(this).innerHTML 中的this 是浏览器对象,不是jq对象
这篇关于javascript - $(this).innerHTML取出的是undefined,为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文