1.文本框的样式控制
/*鼠标经过字段时聚集并有蓝色框框提示*/
function onFocusClassName (obj, NowClass)
{
document.getElementById(obj).className = NowClass;
}
/*鼠标指向时聚焦,经过时是一种样式,离开时又恢复原来的样式*/
<textarea onkeyup="sizeCheck(this,200)" name="qksm" id="qksm" value="" cols="19" rows="3" wrap="VIRTUAL" tabIndex="4" onmouseover="this.focus();this.select();" onfocus="onFocusClassName('qksm', 'focus_normal')" onblur="onFocusClassName('qksm', 'blur_normal')" ></textarea>
2.上传附件,用正则表达式判断格式
<html:form action="wwjy.do?method=add" enctype="multipart/form-data" onsubmit="return tijiao()">
<tr>
<td>附件:</td>
<td>
<html:file property="zhqk" value="浏览"></html:file>
</td>
</tr>
</html:form>
function tijiao(){
var bz = document.all.zhqk.value;
if(bz!=""){
reg=//.([^/.]+)$/; //?
var e=reg.exec(bz)[1].toLowerCase(); //?
if(e!="doc"){
alert("上传文件格式错误,请上传word文档!");
return false;
}
}
3.更好的上传方法 CB: CLOB(字符大数据量对象);??回去再看看
sqlserver中定义类型为:image
数据库中存放的就是文件:<二进制数据>,还不是路径了。
原来用的是struts的方法
<html:form action="wwjy.do?method=add" enctype="multipart/form-data" onsubmit="return tijiao()">
<tr>
<td>附件:</td>
<td>
<html:file property="zhqk" value="浏览"></html:file>
</td>
</tr>
<tr>
<td>名称:</td>
<td>
<input type="text" name="title" />
</td>
</tr>
<html:submit value="保存"/>
</html:form>
上传,其它的字段还是用request.getParameter();来取得
org.apache.struts.upload.FormFile file=request.getparameter("zhqk");
InputStream in = file.getInputStream();
插入附件的(图片,文件都可以)
if(in.available()>0){
in.available();}
BinaryStream
下载image类型的文件
<a href="wwjy.do?method=down&ID=<%=vo.getID()%>&filename=zhqk.doc">
<img src="images/edit.gif" border="0" alt="转化情况.doc"/></a>
public ActionForward down....
{
HttpSession session = request.getSession();
String fileName = request.getParameter("filename");
String ID = request.getParameter("ID");
response.setContentType("application/msdownload;charset=GB2312");
String contentDisposition = (new StringBuilder("attachment; filename=")).append(toUtf8String(fileName)).toString();
response.setHeader("Content-Disposition", contentDisposition);
java.io.OutputStream out = response.getOutputStream();
...(部份非重要代码省略)
String sql=select zhqk from wwjy where id="+id;
if(rs.next())
{
byte b[] = new byte[1024];
InputStream in = rs.getBinaryStream("zhqk");
for (int len = 0; (len = in.read(b)) != -1;)
{
out.write(b, 0, len); //下载了。。。
out.flush();
}
out.close();
in.close();
}
return null;
}
4.window.dialogArguments.window.location (弹出窗口中的代码)
window.close(); //关闭子窗口
//window.dialogArguments 对应父窗口 这样做是为了在子窗口中操作后,跳到action,回来时不是子窗口,而是返回父窗口
5.点击表格一行,颜色变,还可以做各种添加删除都操作
function dj(name){
name.bgColor="#cccfff";
var ID=name.getid;
document.all.ID.value=ID;
}
<tr onclick="dj(this)" getid="<%=vo.getID()%>">
<input type="hidden" name="ID" value="" >
var ID=document.all.xh.value;//取值,看哪一行被选中
document.all.ID.value="";//清空存储值
if(ID!=""){
url="<%=path %>/wwjy.do?method=edit&ID="+ID;
window.showModalDialog(url,arguemnts,"dialogHeight:330px;dialogWidth:320px;dialogTop:270px;dialogLeft:300px;status:no;unadorned:no;scroll:no;resizable:no;edge:sunken;");
}
else{ alert("请选择您要修改的记录!") }
}
6.查一下
var arguemnts = new Object();
arguemnts.window = window; //这是做什么用的???上下级窗口的转来转出。。。糊里糊涂
window.showModalDialog(....
var arguemnts = new Object();
7.打印一个页面(样式为黑细线)
写法:
<table border="1" style="border-collapse: collapse;" cellspacing="0" cellpadding="0">
1 建立HTML的Object标签,调用WebBrowser控件。
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 VIEWASTEXT/>
直接弹出打印预览了。
2 <body onload="dayan()">
<script type="text/javascript">
function dayan(){
document.all.WebBrowser.ExecWB(7,1);//(7,1)是打印预览,(6,6)是直接打印,(8,1)是页面设置
}
</script>
8.