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.上傳附件,用Regex判斷格式
<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.