我使用下面的代码。document.getElementById没有得到新输入的HTML文本输入值
这个想法是打印名为“PrintThis”的div的内容,其中包含文本输入区“textarea1”。
问题是,getElementById只能返回加载页面的字符串;在这种情况下“蛋糕”。
如果我通过点击并在页面上输入“textarea1”将“cake”更改为“pie”,那么printContents仍然有“cake”而不是“pie”。
<html>
<head> </head>
<script type="text/javascript">
function printFunction(divName) {
var printContents = document.getElementById(divName).innerHTML;
//Now call a script to print (not included)
}
</script>
<body>
<div id="printThis" name="printThis">
<textarea id="textarea1" cols="1" rows="10" style="width:95%!important;" ">cake</textarea>
</div>
<input type="button" value="Print Div" onClick="printFunction('printThis')">
</body></html>
在我的生产版本我也使用AJAX来发布文字面积值回服务器,所以在理论上可以使用页面刷新,但不跑,我尝试使用这些选项。
document.location.reload(true);
window.top.location=window.top.location;
生产版本也有jQuery可用。
试图让与jQuery VAL()函数... – Shail 2014-08-28 10:53:48
http://stackoverflow.com/q/14939010/1700321值。 – 2014-08-28 11:04:53
好的,我会看看jQuery选项,但记住在生产版本中,printThis Div会有多个元素。 – 2014-08-28 11:25:47