<!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对象
写在元素上onclick里面的函数preview,里面的this指向全局对象window,而不是指向该元素
$(this)是jq对象,要用也是$(this).html()啊
$(this)[0].innerHTML;这样
你可以打断点看一下你写的这个$(this)是啥,这里应该指的是window,而不是你想要的td
$(this)是jquery包装的上下文环境,需要其指定方法获取内部静态片段。
两种方式获取:
原生写法: this.innerHTML
jquery: $(this).html()
jq+原生: $(this)[0].innerHTML 或者是 this.get(0).html()
到底想原生还是jq