07/9/15
今天做东西发现了一个很奇怪的问题,明明字段正确,数据库却总在抱"索引描述符",错误. 烦恼了很久.
通过上网问和修改,发现读数据库的时候,必须按数据库设计的字段顺序读取,否则就会索引描述符,的数据库错误.
这算一个收获,也算一个教训.平常还真没注意..以前做很多东西都没发生过这个错误.奇怪..看来以前习惯很好.
今天用到的一个知识:JS实现取下拉列表框的文本和值
<
script
>
function change()
... {
var f=document.getElementById("fund");
var fundvalue=f.value;
var fundtext=f.options[document.getElementById("fund").options.selectedIndex].text;
document.getElementById("a").value=fundvalue;
document.getElementById("b").value=fundtext;
}
</ script >
< select name = " fund " onchange = " change() " >
< option value = " 1 " > 第1个 </ option >
< option value = " 2 " > 第2个 </ option >
< option value = " 3 " > 第3个 </ option >
</ select >
< input type = " text " id = " a " />
< input type = " text " id = " b " />
function change()
... {
var f=document.getElementById("fund");
var fundvalue=f.value;
var fundtext=f.options[document.getElementById("fund").options.selectedIndex].text;
document.getElementById("a").value=fundvalue;
document.getElementById("b").value=fundtext;
}
</ script >
< select name = " fund " onchange = " change() " >
< option value = " 1 " > 第1个 </ option >
< option value = " 2 " > 第2个 </ option >
< option value = " 3 " > 第3个 </ option >
</ select >
< input type = " text " id = " a " />
< input type = " text " id = " b " />
今天在做项目的时候我突然想到基金的详单和用户详单要打印.去网上找到以下代码实现了此功能
JS实现局部打印和预览:
第一种:
JS 实现简单的页面局部打印
function preview(oper)
... {
if (oper < 10)...{
bdhtml=window.document.body.innerHTML;//获取当前页的html代码
sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else ...{
window.print();
}
}
使用很简单 将页面内要打印的内容加入中间 <!-- startprint1 --> XXXXX <!-- endprint1 -->
再加个打印按纽 onclick = preview( 1 )
function preview(oper)
... {
if (oper < 10)...{
bdhtml=window.document.body.innerHTML;//获取当前页的html代码
sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else ...{
window.print();
}
}
使用很简单 将页面内要打印的内容加入中间 <!-- startprint1 --> XXXXX <!-- endprint1 -->
再加个打印按纽 onclick = preview( 1 )
第二中:组件法
WebBrowser是IE内置的浏览器控件,无需用户下载.
一、WebBrowser控件
< object ID = ' WebBrowser ' WIDTH = 0 HEIGHT = 0 CLASSID = ' CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 ' ></ object >
二、WebBrowder控件的方法
// 打印
WebBrowser1.ExecWB( 6 , 1 );
// 打印设置
WebBrowser1.ExecWB( 8 , 1 );
// 打印预览
WebBrowser1.ExecWB( 7 , 1 );
关于这个组件还有其他的用法,列举如下:
WebBrowser.ExecWB( 1 , 1 ) 打开
Web.ExecWB( 2 , 1 ) 关闭现在所有的IE窗口,并打开一个新窗口
Web.ExecWB( 4 , 1 ) 保存网页
Web.ExecWB( 6 , 1 ) 打印
Web.ExecWB( 7 , 1 ) 打印预览
Web.ExecWB( 8 , 1 ) 打印页面设置
Web.ExecWB( 10 , 1 ) 查看页面属性
Web.ExecWB( 15 , 1 ) 好像是撤销,有待确认
Web.ExecWB( 17 , 1 ) 全选
Web.ExecWB( 22 , 1 ) 刷新
Web.ExecWB( 45 , 1 ) 关闭窗体无提示
但是打印是会把整个页面都打印出来的,页面里面有什么东西就打印出来,我们有时候只需要打印数据表格,这时我们就要写一个样式了:把不想打印的部份隐藏起来:
样式内容:
< style type = " text/css " media = print >
.noprint ... {display : none }
</ style >
然后使用样式就可以:
< p class = " noprint " > 不需要打印的地方 </ p >
代码如下:
< script language = " javascript " >
function printsetup() ... {
// 打印页面设置
wb.execwb(8,1);
}
function printpreview() ... {
// 打印页面预览
wb.execwb(7,1);
}
function printit()
... {
if (confirm('确定打印吗?')) ...{
wb.execwb(6,6)
}
}
</ script >
< OBJECT classid = " CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 " height = 0 id = wb name = wb width = 0 ></ OBJECT >
< input type = button name = button_print value = " 打印 " class = " noprint " onclick = " javascript:printit() " >
< input type = button name = button_setup value = " 打印页面设置 " class = " noprint " onclick = " javascript:printsetup(); " >
< input type = button name = button_show value = " 打印预览 " class = " noprint " onclick = " javascript:printpreview(); " >
一、WebBrowser控件
< object ID = ' WebBrowser ' WIDTH = 0 HEIGHT = 0 CLASSID = ' CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 ' ></ object >
二、WebBrowder控件的方法
// 打印
WebBrowser1.ExecWB( 6 , 1 );
// 打印设置
WebBrowser1.ExecWB( 8 , 1 );
// 打印预览
WebBrowser1.ExecWB( 7 , 1 );
关于这个组件还有其他的用法,列举如下:
WebBrowser.ExecWB( 1 , 1 ) 打开
Web.ExecWB( 2 , 1 ) 关闭现在所有的IE窗口,并打开一个新窗口
Web.ExecWB( 4 , 1 ) 保存网页
Web.ExecWB( 6 , 1 ) 打印
Web.ExecWB( 7 , 1 ) 打印预览
Web.ExecWB( 8 , 1 ) 打印页面设置
Web.ExecWB( 10 , 1 ) 查看页面属性
Web.ExecWB( 15 , 1 ) 好像是撤销,有待确认
Web.ExecWB( 17 , 1 ) 全选
Web.ExecWB( 22 , 1 ) 刷新
Web.ExecWB( 45 , 1 ) 关闭窗体无提示
但是打印是会把整个页面都打印出来的,页面里面有什么东西就打印出来,我们有时候只需要打印数据表格,这时我们就要写一个样式了:把不想打印的部份隐藏起来:
样式内容:
< style type = " text/css " media = print >
.noprint ... {display : none }
</ style >
然后使用样式就可以:
< p class = " noprint " > 不需要打印的地方 </ p >
代码如下:
< script language = " javascript " >
function printsetup() ... {
// 打印页面设置
wb.execwb(8,1);
}
function printpreview() ... {
// 打印页面预览
wb.execwb(7,1);
}
function printit()
... {
if (confirm('确定打印吗?')) ...{
wb.execwb(6,6)
}
}
</ script >
< OBJECT classid = " CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 " height = 0 id = wb name = wb width = 0 ></ OBJECT >
< input type = button name = button_print value = " 打印 " class = " noprint " onclick = " javascript:printit() " >
< input type = button name = button_setup value = " 打印页面设置 " class = " noprint " onclick = " javascript:printsetup(); " >
< input type = button name = button_show value = " 打印预览 " class = " noprint " onclick = " javascript:printpreview(); " >
以上为今天的收获.....Struts写JAVA程序基本没遇到什么问题,很顺利..加油...