公司的項目中用到了這個新消息提示的效果,主要用于提示用戶有新消息。具體實現代碼如下:
01 |
var newMessageRemind={ |
02 |
_step: 0, |
03 |
_title: document.title, |
04 |
_timer: null , |
05 |
//顯示新消息提示 |
06 |
show: function (){ |
07 |
var temps = newMessageRemind._title.replace( "【 】" , "" ).replace( "【新消息】" , "" ); |
08 |
newMessageRemind._timer = setTimeout( function () { |
09 |
newMessageRemind.show(); |
10 |
//這里寫Cookie操作 |
11 |
newMessageRemind._step++; |
12 |
if (newMessageRemind._step == 3) { newMessageRemind._step = 1 }; |
13 |
if (newMessageRemind._step == 1) { document.title = "【 】" + temps }; |
14 |
if (newMessageRemind._step == 2) { document.title = "【新消息】" + temps }; |
15 |
}, 800); |
16 |
return [newMessageRemind._timer, newMessageRemind._title]; |
17 |
}, |
18 |
//取消新消息提示 |
19 |
clear: function (){ |
20 |
clearTimeout(newMessageRemind._timer ); |
21 |
document.title = newMessageRemind._title; |
22 |
//這里寫Cookie操作 |
23 |
} |
24 |
|
25 |
}; |
調用顯示新消息提示:newMessageRemind.show();
調用取消新消息提示:newMessageRemind.clear();
查看demo:http://www.css88.com/demo/newMessageRemind/
另:單純的這個代碼會出現這么一個問題:
就是當你打開一個站點很多張頁面的時候,如過有新消息,那么所有頁面都會不停的閃,當你查看消息后其他頁面仍會提示。
我們公司是通過使用Cookie的方式解決的,當查看新消息后所有標題閃動的頁面將全部取消提示。
聲明: 本文采用 BY-NC-SA 協議進行授權 | WEB前端開發
轉載請注明轉自《標題欄新消息提示效果》
今天一個剛學js的朋友給了我一段代碼問為什么方法不執行,代碼如下:
1 |
function makefunc(x) { |
2 |
return function (){ |
3 |
return x; |
4 |
} |
5 |
} |
6 |
alert(makefunc(0)); |
其實不是不執行,只是朋友的意思這里alert出來的應該是“0”,而不是function (){return x;}。
不是腳本寫錯了,只是沒搞懂return,從當前函數退出,并從那個函數返回一個值。如果返回的是一個函數,那么返回的也是函數本身。
可以這樣修改上面的代碼,就是alert(makefunc(0)()):
1 |
function makefunc(x) { |
2 |
return ( function (){ |
3 |
return x; |
4 |
})(); |
5 |
} |
6 |
alert(makefunc(0)()); |
如果要返回函數執行的結果那么首先要讓這個函數執行,例如:
1 |
function makefunc(x) { |
2 |
return ( function (){ |
3 |
return x; |
4 |
})(); |
5 |
} |
6 |
alert(makefunc(0)); |
這里有一個匿名函數,
1 |
( function (){ |
2 |
return x; |
3 |
})(); |
在第一個括號內是匿名函數,第二個括號用于調用該匿名函數,您可以在第二個括號中傳入所需的參數。例如:
1 |
( function ( x , y){ |
2 |
alert( x + y); |
3 |
})(2 ,3 ); |
聲明: 本文采用 BY-NC-SA 協議進行授權 | WEB前端開發
轉載請注明轉自《return閉包函數》
哇,居然頁面倒過來了,頁頭和頁腳翻了一個根頭,其實我以前還在想,背景圖片是不是可以這樣呢,今天至少在頁面上看到了。
真好奇,立即啟動火狐看了一下,哈哈,找到原因了,馬上在試了一下IE,搞定,也OK,哈哈,如果不知道的同學們,我想你們也想知道這是怎么回事吧。
其實就是這個東東在做怪。。。
-moz-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
三行代碼,分別用來支持moz,webkit和IE的內核的瀏覽器。
我們看看克軍是怎么做的呢,他使用了JS,讓代碼立即執行的方式。。給頁面增加一個<sytle>和相應的樣式,并且為body增加相應的class.下面我將他的js代碼貼出來。嘿嘿!
;(function(){
var d = document, n = d.createElement('style'), r='.flip { -moz-transform: rotate(180deg);-webkit-transform: rotate(180deg);filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); }';
n.type = 'text/css';
if(n.styleSheet)
{
n.styleSheet.cssText = r;
}
else
{
n.appendChild(d.createTextNode(r))
}
d.getElementsByTagName('head')[0].appendChild(n);
d.body.className += ' flip';
}
為了使用document方便,他把document傳給了變量d,建立了一個style標簽為變量n,把樣式的內容傳給
了變量r,克軍的命名都很簡潔。
在為這個n其實就是style標簽了type這個屬性。
下面是進行判斷頁面中style有不有屬性,如果沒有,直接將r,也就是樣式的內容放入n中。
如果有,就得使用建立文本并且追加的方式。
我不知道我的解釋對不對哈,反正大概意思就是這樣的,歡迎指正。
一切準備就緒以后,就將n添加到head中去,在將class增加到body上,這樣頁面一加載。。。。你的頁面就會被旋轉180度,當然你可以旋轉90度,10度,數字是可以調整的喲。
2010.09.30 今天在使用過程中,最后發現,原來ie只支持4個值,分別旋轉值可以是1,2,3或4。這些數字分別代表90,180,270,或360度旋轉。
ThickBox運行需要的文件
官方下載:
Download thickbox.js or thickbox-compressed.js, ThickBox.css, and the loading graphic (loadingAnimation.gif) to your local machine (or cut and paste the code from the tabs). Along with these three files, a copy of the jQuery JavaScript library is needed. For this site, and ThickBox, I am using the compressed version of jQuery.
首先在 HTML 文件的 head中導入jquery.js 和thickbox.js文件,導入 thickbox.css 文件;并且jquery.js 文件放在前面:
<script src="../Scripts/jquery-latest.pack.js" mce_src="Scripts/jquery-latest.pack.js" type="text/javascript"></script> <script src="../Scripts/thickbox.js" mce_src="Scripts/thickbox.js" type="text/javascript"></script> <link href="../Styles/thickbox.css" mce_href="Styles/thickbox.css" rel="stylesheet" type="text/css" />
最后你只要給元素添加 class=”thickbox” 屬性就可以開始用 thickbox
實現了一張圖片的彈出展示功能:
<a href="”bg.jpg”" mce_href="”bg.jpg”" class=”thickbox” ><img src="”bg.jpg”" mce_src="”bg.jpg”" alt=”圖片”/></a> //只需要指定圖片的class為thickbox彈出框使用方法:
<a href="Default.aspx?keepThis=true&TB_iframe=true&height=400&width=500" title="主頁" class="thickbox" </a> <input onclick="<web.path:path/>/bannedUserList!unBannedUserList?height=400&width=800&inlineId=myOnPageContent" title="彈出層" class="thickbox" type="button" value="Ban Another" /> //內嵌內容 <input alt="#TB_inline?height=300&width=400&inlineId=myOnPageContent" title="標題" class="thickbox" type="button" value="Show" /> <a href="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" class="thickbox">顯示隱藏內容a> //遮罩層 URL后面加?KeepThis=true&TB_iframe=true&height=400&width=600 參數字符串中加 modal=true ?KeepThis=true&TB_iframe=true&height=400&width=600&modal=true 這樣當關閉ThickBox時會調用ThickBox iframe (self.parent.tb_remove())內部的一個tb_remove()函數 所有其他參數字符都必須在TB_iframe 參數之前。URL中所有"TB" 之后的將被移除。 <a href="index.html?keepThis=true&TB_iframe=true&height=250&width=400" title="標題" class="thickbox">打開一個頁面</a> <a href="index.html?keepThis=true&TB_iframe=true&height=300&width=500" title="標題" class="thickbox">打開一個頁面</a> <a href="index.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="標題" class="thickbox">打開一個頁面</a>
自定義設置:
1、彈出窗口(div)右上角的關閉按鈕為顯示為"close or esc key",而不是中文的; 如果想把它變成[X]或"關閉"應該怎么來辦呢?
將thickbox.js文件打開,查找關鍵字"or esc key",將其刪除,并將前面的close更改為[X]或"關閉",然后把文件另存為UTF-8格式,如果不保存為UTF-8的話,將會出現亂碼。2、thickbox 彈出層的遮住層透明度修改
打開thickbox.css查找.TB_overlayBG 進行更改
.TB_overlayBG { background-color:#000; filter:alpha(opacity=75); -moz-opacity: 0.75; opacity: 0.75; }
3、關閉層:如果我們需要自己添加一個關閉按鈕或者圖片可以使用:
onclick="self.parent.tb_remove();"
4、關閉層刷新父頁面,修改關閉方法 :
function tb_remove() { $("#TB_imageOff").unbind("click"); $("#TB_closeWindowButton").unbind("click"); $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();}); $("#TB_load").remove(); if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 $("body","html").css({height: "auto", width: "auto"}); $("html").css("overflow",""); } document.onkeydown = ""; document.onkeyup = ""; //刷新父頁面,未指定 window.location.reload(); return false; }
5、thickbox插件默認情況是點擊灰色的遮罩層就會關閉取消
把兩個$("#TB_overlay").click(tb_remove);去掉就可以取消掉
6、updatepanel回發后thickbox失效的解決方法
只需把以下代碼粘貼至頁面中就OK了。 <script type="text/javascript" language="javascript"> function pageLoad() { var isAsyncPostback = Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack(); if (isAsyncPostback) { tb_init('a.thickbox, area.thickbox, input.thickbox'); } } </script>
<a >OECSPACE</a>
<a href="boxs.html?keepThis=true&TB_iframe=true&height=100&width=220&modal=true" title="ThickBox 3.1:modal=true表示禁用title,去掉即可顯示title及可自動關閉" class="thickbox">Open iFrame Modal</a>
<a href="box.html?height=350&width=350&modal=true" title="ThickBox 3.1:Ajax載入,頁面無法查看源代碼" class="thickbox">Example</a>
<a href="#TB_inline?height=200&width=300&inlineId=hiddenModalContent&modal=true" title="ThickBox 3.1:鏈接顯示隱藏層" class="thickbox">Show hidden modal content</a>
<div id="hiddenModalContent" style="display:none">
<p>ThickBox hidden modal content. Click to hide.</p>
<p style="text-align:center"><input type="submit" value=" O K " onclick="tb_remove()" /></p>
</div>
<input alt="#TB_inline?height=150&width=400&inlineId=myOnPageContent " title="ThickBox 3.1:按鈕顯示隱藏層" class="thickbox" type="button" value="Show" />
<div id="myOnPageContent" style="display:none">
<p>ThickBox hidden modal content.Auto Hide.</p>
</div>
<a href="images/plant1.jpg" title="plant" class="thickbox"><img src="images/plant1_t.jpg" alt="ThickBox 3.1" /></a>
<a href="images/plant1.jpg" title="plant1" class="thickbox" rel="gallery-plants"><img src="images/plant1_t.jpg" alt="ThickBox 3.1 1" /></a>
<a href="images/plant2.jpg" title="plant2" class="thickbox" rel="gallery-plants"><img src="images/plant2_t.jpg" alt="ThickBox 3.1 2" /></a>
<a href="images/plant3.jpg" title="plant3" class="thickbox" rel="gallery-plants"><img src="images/plant3_t.jpg" alt="ThickBox 3.1 3" /></a>
$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");
$("#TB_window").append("<img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");
<body>
<p align="center">
你已經上傳成功,
<a href="upload.jsp">請返回</a>
</p>
</body>
</html>
========================================================================
后臺:一共需要三個4個java文件
1. <FileMes>
package upload.until;
/**
* Created by IntelliJ IDEA.
* User: lvjiachun
* Date: 2006-5-3
* Time: 7:51:11
* To change this template use File | Settings | File Templates.
*/
public class FileMes {
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
private String filePath;
}
2.<FileSelect >
package upload.until;
/**
* Created by IntelliJ IDEA.
* User: lvjiachun
* Date: 2006-5-3
* Time: 7:51:23
* To change this template use File | Settings | File Templates.
*/
public class FileSelect {
private String fileName;
private String fileURL;
private String type;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileURL() {
return fileURL;
}
public void setFileURL(String fileURL) {
this.fileURL = fileURL;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
3.<UploadUntil >
package upload.until;
import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequestWrapper;
import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest;
import com.opensymphony.webwork.ServletActionContext;
import java.util.List;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Calendar;
import java.io.*;
/**
* Created by IntelliJ IDEA.
* User: lvjiachun
* Date: 2006-5-3
* Time: 7:51:00
* To change this template use File | Settings | File Templates.
*/
public class UploadUntil {
public static List<FileMes> Upload(String smallPath) throws IOException {
List<FileMes> fileMesList = new ArrayList<FileMes>();
String path = smallPath;
System.out.println("PATH 2:" + path);
MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) ServletActionContext.getRequest();
if (multiWrapper == null) return null;
Enumeration e = multiWrapper.getFileNames();
int i = 0;
//===============================================================//
//這個是單文件上傳的代碼;!!如果想做單文件上傳,把注釋掉的代碼去掉就可以了
// while (e.hasMoreElements()) {
// String inputValue = (String) e.nextElement();
// String contentType = multiWrapper.getContentType(inputValue);
// String flie1 = multiWrapper.getFilesystemName(inputValue);
// String fileName = flie1;
// System.out.println("FileName underfinded:" + fileName);
// String savePath = path + fileName;
// File file = multiWrapper.getFile(inputValue);
// if (file != null) {
// InputStream inStream = new FileInputStream(file.getPath());
// FileMes fm = new FileMes();
// fm.setFileName(flie1);
// System.out.println("FileName:" + fm.getFileName());
// System.out.println("SmallPath in UploadUntil.java" + smallPath);
// fm.setFilePath(smallPath + fileName);
// System.out.println("FilePath:" + fm.getFilePath());
// fileMesList.add(fm);
// System.out.println("SavePath:" + savePath);
// FileOutputStream fs = new FileOutputStream(savePath);
// byte[]buffer = new byte[1444];
// int length;
// int bytesum = 0;
// int byteread = 0;
// while ((byteread = inStream.read(buffer)) != -1) {
// bytesum += byteread;
// fs.write(buffer, 0, byteread);
// }
//============================================================//
// 下面這個是多文件上傳-------------------
while (e.hasMoreElements()) {
String inputValue = (String) e.nextElement();
String contentType = multiWrapper.getContentType(inputValue);
String flie1 = multiWrapper.getFilesystemName(inputValue);
String fileName = Calendar.getInstance().getTime().getTime() + "-" + i + flie1;
String savePath = path + fileName;
File file = multiWrapper.getFile(inputValue);
if (file != null) {
InputStream inStream = new FileInputStream(file.getPath()); //讀入原文件
FileMes fm = new FileMes();
fm.setFileName(flie1);
fm.setFilePath(smallPath + fileName);
fileMesList.add(fm);
FileOutputStream fs = new FileOutputStream(savePath);
byte[] buffer = new byte[1444];
int length;
int bytesum = 0;
int byteread = 0;
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字節數 文件大小
fs.write(buffer, 0, byteread);
}
//==============================================================//
inStream.close(); //關閉輸入流
i++;
if (file.exists()) {
file.delete();
} //如果上傳的文件存在則將其刪除;
}
}
return fileMesList;
}
}
4.也就是最后一個,action<UploadfilesAction>
package upload.fileupload;
import com.opensymphony.xwork.ActionSupport;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ModelDriven;
import upload.until.FileSelect;
/**
* Created by IntelliJ IDEA.
* User:lvjiachun
* Date: 2006-5-3
* Time: 7:52:34
* To change this template use File | Settings | File Templates.
*/
public class UploadfilesAction extends ActionSupport implements Action, ModelDriven {
FileSelect fileMes = new FileSelect();
public String upload() throws Exception {
String smallPath = fileMes.getFileURL();
System.out.println(smallPath+"xiaosao");
java.io.File myFilePath = new java.io.File(smallPath);
if (smallPath != null) {
if (!myFilePath.exists()) {
myFilePath.mkdir();
System.out.println("*******MaKe DIR!*********");
}
}
upload.until.UploadUntil.Upload(smallPath);
return SUCCESS;
}
public Object getModel() {
return fileMes; //To change body of implemented methods use File | Settings | File Templates.
}
}
**********************************************************************
xwork中
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="upload" extends="webwork-default">
<interceptors>
<interceptor name="upload" class="com.opensymphony.webwork.interceptor.FileUploadInterceptor"/>
<interceptor-stack name="uploadStack">
<interceptor-ref name="upload"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="WSStack"/>
<action name="upload" class="upload.fileupload.UploadfilesAction" method="upload">
<result name="success">
<param name="location">/upload/upload-success.jsp</param>
</result>
<interceptor-ref name="uploadStack"/>
<interceptor-ref name="model-driven"/>
</action>
</package>
</xwork>
webwork.properties
在webwork.properties中要加上這段代碼
webwork.multipart.parser=com.opensymphony.webwork.dispatcher.multipart.PellMultiPartRequest
webwork.multipart.saveDir=d:\\ #這個是上傳文件的默認保存路徑#
xiaosao:具體的解析過程不是我寫的,是我工作室boss寫的,我也沒那個能力!具體怎么用
看代碼就足夠了,這個是我在做上傳得時候用到的,開始做的時候沒有任何思路,在網上找
也沒找到,憋了半個月也沒弄出來,用webwork可以得到上傳得文件,但傳得內容只有upload這
幾個字(傳txt時候),后來才清楚是要解析過程的,后臺的前三段代碼就是解析過程,我是個新
手,這個東西做的讓我腦袋都大了,為了大家方便,發到這里,有需要的來看一下!代碼是好
使得,需要自己認真調試!有什么不足給點意見
<ww:textfield label="名稱" name="content.contentName" value="" required="true"/>
<tr>
<td>上傳文件</td>
<td colspan="2">
<input type="file" name="file1"><br/>
<input type="file" name="file2"><br/>
<input type="file" name="file3"><br/>
<input type="file" name="file4"><br/>
<input type="file" name="file5"> <br/>
</td></tr>
<ww:submit value="提交"></ww:submit>
</table>
</form>
在另一個界面,用${param.category}得到,param指的是<c:param>標簽[jstl] ,在xwork中對result可以不用做任何處理,只要告訴它下一個界面是什么就可以了!
其中:${param.categoryId}和${param.testId}是得到上個界面的值得!
2. 如果在兩個頁面傳值,中間經過了一個java文件,那么可以通過xwork進行傳值,具體做法如果下
jsp:
<c:url var="testContent" value="/admin/select_Test_category.action">
<c:param name="model.test_id" value="${test.testId}"/>
<c:param name="model.category_id" value="${test.categoryId}"/>
</c:url>
<a href="${testContent}">編輯</a>
xwork中:
<action name="select_Test_category" class="com.cool.lvjiachun.Select_Test_categoryAction">
<result name="success" type="dispatcher">
<param name="location">/cool/lvjiachun/test_category.jsp</param>
</result>
<result name="alone" type="dispatcher">
<param name="location">
/cool/lvjiachun/editor_test_category.jsp?model.category_id=${model.category_id}</param>
</result>
<interceptor-ref name="WSStack"/>
</action>
看一下result是怎么弄得吧,“?model.category_id=${model.category_id}”,${model.category_id}是第一個jsp“<c:paramname="model.test_id"value="${test.testId}"/>”
里的name,這樣值在下一個界面就可以得到了
下一個jsp,也就是editor_test_category.jsp,
<ww:a href="admin/getTestList.action?model.category_id=${model.category_id}&id=${model.category_id}" value="返回">
返回
</ww:a>
這樣就可以了!
3.如果要經過兩個action,經過一個action后還要經過另一個action才能到下一個jsp,后一個action需要jsp界面的數據,那么可以用重定向redirect,這樣就可以達到你想要的結果!(也可以不用,但要通過數據庫在去查數據,這樣很耗費時間,也麻煩)
例如:
jsp:
<ww:form action="/admin/addTestCategory.action" method="post" validate="true">
<ww:textfield label="添加分類" name="test.testName" required="true"/>
<ww:submit value="添加"></ww:submit>
<ww:url id="listlink" namespace="/admin" action="getTestList" method="getList"></ww:url>
<ww:hidden name="test.categoryId" value="${param.id}"></ww:hidden>
</ww:form>
xwork中:
<action name="addTestCategory" class="com.dream.action.TestCategoryAction" method="insert">
<external-ref name="testcategoryDAO">testcategoryDAOProxy</external-ref>
<result name="success" type="redirect">
<param name="location">/admin/getTestList.action?id=${test.categoryId}&model.category_id=${test.categoryId}</param>
</result>
<result name="input" type="redirect">
<param name="location">/admin/getTestList.action?model.category_id=${test.categoryId}&id=${test.categoryId}</param>
</result>
<interceptor-ref name="WSStack"/>
<interceptor-ref name="validationWorkflowStack"/>
</action>
“${param.id}”,看到了吧,它就是1的方法得到的!!!
其實這些也是經過高人指點才做到的,發在這里有興趣的大家分享一下,也許我描述不對,但我相信大家看例子也可以看懂得!如果有什么不對的地方,也請前輩們諒解并給予糾正!