javascript 打印预览的实现
引自:http://blog.csdn.net/lsj19830812/archive/2007/10/25/1843578.aspx
a.jsp是要打印的页面
<html>
<head>
<script language="javascript">
function fmtPrint(printPlace,w,h){
var sarg=new Array();
var sdata=document.all.item(printPlace);
sarg[0]=sdata.outerHTML;
window.showModalDialog("print.jsp",sarg,"dialogWidth:"+w+"px;dialogHeight:"+h+"px;center:yes;help:no;status:no;resizable:yes");
return;
}
</script>
</head>
<body>
<div id="printPlace">
希望打印的内容写在里面
...........
...........
...........
...........
...........
</div>
<img onClick="fmtPrint('printPlace', 800, 600);" name="Print" border="0" style="cursor:hand" src="images/dayin.gif">
</body>
</html>
print.jsp是打印预览页面
<html>
<head>
<base target="_self">
<script language="javascript">
<!--
var dada = dialogArguments;
var da1 = dada[1];
function loaddatas(){
var tagBody;
var pf = document.all.item('printfield');
pf.insertAdjacentHTML('beforeEnd',da1);
var removeRadio = document.all.tags("input");
for(var i=0; i<removeRadio.length; i++){
tagBody = removeRadio[i];
if (tagBody.getAttribute("type") == "radio"||tagBody.getAttribute("type") == "checkbox")
{
tagBody.style.display = 'none';
}
}
var removeHref = document.all.tags("A");
for(var i=0; i<removeHref.length; i++){
tagBody = removeHref[i];
if (tagBody.getAttribute("href") != null)
{
tagBody.setAttribute("href","javascript:void(0)");
}
}
var removeImg = document.all.tags("img");
for(var i=0; i<removeImg.length; i++)
相关文档:
// 浏览器显示区域的宽和高,向下还原后值会变小。
document.body.clientWidth;
document.body.clientHeight;
// 与上面的两个值相比,我觉得就是加上了滚动条的宽和高
document.body.offsetWidth;
document.body.offsetHeight;
// 整个网页的高度和宽度,包括滚动条中没有显示出来的
document.bod ......
JavaScript 语法集锦
click() 对象.click() 使对象被点击。
closed 对象.closed 对象窗口是否已关闭 true/false
clearTimeout(对象) 清除已设置的setTimeout对象
clearInterval(对象) 清除已设置的setInterval对象
confir ......
window ->perferences->myeclipse->Files and Eidtors ->javaScript
因为MyEclipse保存js文件,中文会出现乱码。按上述方法将编码格式改成中文的编码
实在不行就打开原先的原稿js的文件,复制,粘贴。。。 ......
转化为Boolean类型
所有JavaScript中的值都能隐式的转化为Boolean类型,比如:
0 == false; // true
1 == true; // true
'' == false // true
null == false // true
但是这些值都不是Boolean类型。
因此当我们使用三个等 ......