js中alert彈出窗口換行用"\n"

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的岫巖網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
如果這個(gè)不可以的話就是"\\n"
比如:
script?type="text/javascript"
alert("hello?\n?world!");
/script
不想用點(diǎn)擊,直接執(zhí)行,那么你肯定就不能用onclick事件了。
在網(wǎng)頁中JS函數(shù)自動(dòng)執(zhí)行常用三種方法
在HTML中的Head區(qū)域中,有如下函數(shù):
SCRIPT
LANGUAGE="JavaScript"
functionn
MyAutoRun()
{
//以下是您的函數(shù)的代碼,請(qǐng)自行修改先!
alert("函數(shù)自動(dòng)執(zhí)行哦!");
}
/SCRIPT
下面,我們就針對(duì)上面的函數(shù),讓其在網(wǎng)頁載入的時(shí)候自動(dòng)運(yùn)行!
①第一種方法
將如上代碼改為:
SCRIPT
LANGUAGE="JavaScript"
functionn
MyAutoRun()
{
//以下是您的函數(shù)的代碼,請(qǐng)自行修改先!
alert("函數(shù)自動(dòng)執(zhí)行哦!");
}
window.onload=MyAutoRun();
//僅需要加這一句
/SCRIPT
②第二種方法
修改網(wǎng)頁的Body為:
body onLoad="MyAutoRun();"
或者改為:
body onLoad="javascript:MyAutoRun();"
③第三種方法
使用JS定時(shí)器來間斷性的執(zhí)行函數(shù):
setTimeout("MyAutoRun()",1000); //隔1000毫秒就執(zhí)行一次MyAutoRun()函數(shù)
實(shí)現(xiàn)方法,將最上面的那JS函數(shù),改為:
SCRIPT
LANGUAGE="JavaScript"
functionn
MyAutoRun()
{
//以下是您的函數(shù)的代碼,請(qǐng)自行修改先!
alert("函數(shù)自動(dòng)執(zhí)行哦!");
}
setTimeout("MyAutoRun()",1000);
//這樣就行拉
/SCRIPT
在javabean里設(shè)計(jì)package Date;
public class SplitPage {
//分頁請(qǐng)求時(shí),請(qǐng)求標(biāo)識(shí)參數(shù)
final public static String FIRSTPAGE="first";//請(qǐng)求第一頁
final public static String PREVIOUSEPAGE="previous";//請(qǐng)求上一頁
final public static String NEXTPAGE="next";//請(qǐng)求下一頁
final public static String LASTPAGE="last";//請(qǐng)求最后一頁
private int pageRows=10;//每頁顯示記錄數(shù),默認(rèn)10條,可以在頁面設(shè)置
private int totalRows=0;//總的記錄數(shù),這個(gè)參數(shù)由NoteDAO對(duì)象提供
private int currentPage=1;//當(dāng)前顯示的頁面編號(hào),默認(rèn)第一頁
private int firstPage=1;//首頁位置,默認(rèn)第一頁
private int totalPages=1;//總的頁面數(shù)量,默認(rèn)就一頁
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getFirstPage() {
return firstPage;
}
public void setFirstPage(int firstPage) {
this.firstPage = firstPage;
}
public int getPageRows() {
return pageRows;
}
public void setPageRows(int pageRows) {
if(pageRows==0)throw new ArithmeticException();
this.pageRows = pageRows;//如果pageRows被設(shè)置為零,應(yīng)當(dāng)拋出異常.
//修改每頁顯示記錄數(shù),將會(huì)直接影響總頁面數(shù),所以要同時(shí)修改
this.totalPages=(this.totalRows%this.pageRows==0)?this.totalRows/this.pageRows:this.totalRows/this.pageRows+1;
}
public int getTotalRows() {
return totalRows;
}
//設(shè)置分頁對(duì)象的總記錄屬性后,就應(yīng)該根據(jù)每頁面顯示記錄數(shù),計(jì)算得到總的頁面數(shù)
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
//計(jì)算總的頁面數(shù)(或最后的頁面號(hào)),兩個(gè)整數(shù)相除如果剛好除盡,值就是相除后的商,否則如果有余數(shù),商應(yīng)當(dāng)還加1.
this.totalPages=(this.totalRows%this.pageRows==0)?this.totalRows/this.pageRows:this.totalRows/this.pageRows+1;
}
//不應(yīng)該提供方法設(shè)置總頁面數(shù),它是計(jì)算得到的
//但應(yīng)當(dāng)提供獲取總頁面數(shù)的方法.
public int getTotalPages() {
return totalPages;
}
//根據(jù)請(qǐng)求頁面的標(biāo)識(shí)參數(shù),重新計(jì)算當(dāng)前要顯示的頁面
//核心方法,實(shí)現(xiàn)分頁顯示功能.
public int confirmPage(String flag){
int newPage=this.currentPage;
if(flag!=null){//flag只可能是下面值之一
if(flag.equals(SplitPage.FIRSTPAGE)){
newPage=1;
}else if(flag.equals(SplitPage.LASTPAGE)){
newPage=this.totalPages;
}else if(flag.equals(SplitPage.NEXTPAGE)){
//頁面總數(shù)和當(dāng)前頁面編號(hào)相等嗎,如果是那么頁面編號(hào)不往后走,否則頁面編號(hào)加一
newPage=(this.totalPages==this.currentPage)?this.currentPage:this.currentPage+1;
}else if(flag.equals(SplitPage.PREVIOUSEPAGE)){
//第一個(gè)頁面和當(dāng)前頁面相等嗎,如果是那么頁面編號(hào)不往前走,否則頁面編號(hào)減一
newPage=(this.firstPage==this.currentPage)?this.currentPage:this.currentPage-1;
}else{//否則是一個(gè)數(shù)字字符串
int tpage=Integer.parseInt(flag.trim());
newPage=tpage;
}
}else{//如果請(qǐng)求標(biāo)識(shí)參數(shù)為空,那么當(dāng)前頁碼不變
newPage=this.currentPage;
}
//在返回前設(shè)置當(dāng)前頁面
this.setCurrentPage(newPage);
return newPage;
}
}
參考代碼如下:
!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?""
html?xmlns=""?
head
title/title
script?type="text/javascript"?language="javascript"?src=""/script
script?type="text/javascript"?language="javascript"
$(function()?{
$("#right").click(function()?{
var?roll?=?$("div/div",?{?css:?{?position:?"absolute",?border:?"solid?1px?#999",?left:????"806px",?top:?"10px",?height:?"494px",?width:?"1px",?background:?????????????????????"#fff"}}).appendTo($("#book").parent());
$(roll).animate({
left:?"10px",
width:?"398px"
},?1000,?function()?{
$("#left").css({"background":"#fff"});
$(roll).fadeOut(300,?function()?{
$(roll).remove();
})
});
});
});
/script
/head
body?style="padding:5px;margin:0;"
div?id="book"?style="width:797px;height:494px;background:#ccc;border:solid?6px?#ccc;"
div?id="left"?style="width:398px;height:494px;float:left;background:url()?no-repeat?top?left;cursor:pointer;"/div
div?id="right"?style="width:398px;height:494px;float:left;background:#fff;cursor:pointer;margin-left:1px;text-align:right;"p?style="margin-top:470px;font-size:12px;color:#999;"點(diǎn)這翻頁??/p/div
/div
/body
/html
四個(gè)按鈕對(duì)應(yīng)四張圖片唄 首先你的jsp頁面有一張圖片 img id="img" src=""/
4個(gè)按鈕input id="inp1" type="button" onclick="change1()"/
input id="inp2" type="button" onclick="change2()"/
...
script:
function change1(){
document.getElementById('img').src="第一張圖片的地址";
}
function change2(){
document.getElementById('img').src="第二張圖片的地址";
}
。。。
js靜態(tài)分頁,
你可以參考一下
style
* {
font-size:10.2pt;
font-family:tahoma;
line-height:150%;
}
.divContent
{
border:1px solid red;
background-color:#FFD2D3;
width:500px;
word-break:break-all;
margin:10px 0px 10px;
padding:10px;
}
/style
header
div id="divPagenation"/div
div id="divContent"/div
footer
script language="jscript"
!--
s="p女老師竭力向孩子們證明,學(xué)習(xí)好功課的重要性。 /pp她說:“牛頓坐在樹下,眼睛盯著樹在思考,這時(shí),有一個(gè)蘋果落在他的頭上,于是他發(fā)現(xiàn)了萬有引力定律,孩子們,你們想想看,做一位偉大的科學(xué)家多么好,多么神氣啊,要想做到這一點(diǎn),就必須好好學(xué)習(xí)。” /pp“班上一個(gè)調(diào)皮鬼對(duì)此并不滿意。他說:“興許是這樣,可是,假如他坐在學(xué)校里,埋頭書本,那他就什么也發(fā)現(xiàn)不了啦。” /pp女老師竭力向孩子們證明,學(xué)習(xí)好功課的重要性。 /pp她說:“牛頓坐在樹下,眼睛盯著樹在思考,這時(shí),有一個(gè)蘋果落在他的頭上,于是他發(fā)現(xiàn)了萬有引力定律,孩子們,你們想想看,做一位偉大的科學(xué)家多么好,多么神氣啊,要想做到這一點(diǎn),就必須好好學(xué)習(xí)。” /pp“班上一個(gè)調(diào)皮鬼對(duì)此并不滿意。他說:“興許是這樣,可是,假如他坐在學(xué)校里,埋頭書本,那他就什么也發(fā)現(xiàn)不了啦。” /pp女老師竭力向孩子們證明,學(xué)習(xí)好功課的重要性。 /pp她說:“牛頓坐在樹下,眼睛盯著樹在思考,這時(shí),有一個(gè)蘋果落在他的頭上,于是他發(fā)現(xiàn)了萬有引力定律,孩子們,你們想想看,做一位偉大的科學(xué)家多么好,多么神氣啊,要想做到這一點(diǎn),就必須好好學(xué)習(xí)。” /pp“班上一個(gè)調(diào)皮鬼對(duì)此并不滿意。他說:“興許是這樣,可是,假如他坐在學(xué)校里,埋頭書本,那他就什么也發(fā)現(xiàn)不了啦。” /pp女老師竭力向孩子們證明,學(xué)習(xí)好功課的重要性。 /pp她說:“牛頓坐在樹下,眼睛盯著樹在思考,這時(shí),有一個(gè)蘋果落在他的頭上,于是他發(fā)現(xiàn)了萬有引力定律,孩子們,你們想想看,做一位偉大的科學(xué)家多么好,多么神氣啊,要想做到這一點(diǎn),就必須好好學(xué)習(xí)。” /pp“班上一個(gè)調(diào)皮鬼對(duì)此并不滿意。他說:“興許是這樣,可是,假如他坐在學(xué)校里,埋頭書本,那他就什么也發(fā)現(xiàn)不了啦。” /pp女老師竭力向孩子們證明,學(xué)習(xí)好功課的重要性。 /pp她說:“牛頓坐在樹下,眼睛盯著樹在思考,這時(shí),有一個(gè)蘋果落在他的頭上,于是他發(fā)現(xiàn)了萬有引力定律,孩子們,你們想想看,做一位偉大的科學(xué)家多么好,多么神氣啊,要想做到這一點(diǎn),就必須好好學(xué)習(xí)。” /pp“班上一個(gè)調(diào)皮鬼對(duì)此并不滿意。他說:“興許是這樣,可是,假如他坐在學(xué)校里,埋頭書本,那他就什么也發(fā)現(xiàn)不了啦。” /p";
function DHTMLpagenation(content) { with (this)
{
// client static html file pagenation
this.content=content;
this.contentLength=content.length;
this.pageSizeCount;
this.perpageLength=100; //default perpage byte length.
this.currentPage=1;
//this.regularExp=/.+[\?\]page=(\d+)/;
this.regularExp=/\d+/;
this.divDisplayContent;
this.contentStyle=null;
this.strDisplayContent="";
this.divDisplayPagenation;
this.strDisplayPagenation="";
arguments.length==2?perpageLength=arguments[1]:'';
try {
divExecuteTime=document.createElement("DIV");
document.body.appendChild(divExecuteTime);
}
catch(e)
{
}
if(document.getElementById("divContent"))
{
divDisplayContent=document.getElementById("divContent");
}
else
{
try
{
divDisplayContent=document.createElement("DIV");
divDisplayContent.id="divContent";
document.body.appendChild(divDisplayContent);
}
catch(e)
{
return false;
}
}
if(document.getElementById("divPagenation"))
{
divDisplayPagenation=document.getElementById("divPagenation");
}
else
{
try
{
divDisplayPagenation=document.createElement("DIV");
divDisplayPagenation.id="divPagenation";
document.body.appendChild(divDisplayPagenation);
}
catch(e)
{
return false;
}
}
DHTMLpagenation.initialize();
return this;
}};
DHTMLpagenation.initialize=function() { with (this)
{
divDisplayContent.className=contentStyle!=null?contentStyle:"divContent";
if(contentLength=perpageLength)
{
strDisplayContent=content;
divDisplayContent.innerHTML=strDisplayContent;
return null;
}
pageSizeCount=Math.ceil((contentLength/perpageLength));
DHTMLpagenation.goto(currentPage);
DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayPage=function() { with (this)
{
strDisplayPagenation="分頁:";
if(currentPagecurrentPage!=1)
strDisplayPagenation+='a href="javascript:void(0)" onclick="DHTMLpagenation.previous()"上一頁/a??';
else
strDisplayPagenation+="上一頁??";
for(var i=1;i=pageSizeCount;i++)
{
if(i!=currentPage)
strDisplayPagenation+='a href="javascript:void(0)" onclick="DHTMLpagenation.goto('+i+');"'+i+'/a??';
else
strDisplayPagenation+=i+"??";
}
if(currentPagecurrentPage!=pageSizeCount)
strDisplayPagenation+='a href="javascript:void(0)" onclick="DHTMLpagenation.next()"下一頁/a??';
else
strDisplayPagenation+="下一頁??";
strDisplayPagenation+="共 " + pageSizeCount + " 頁,每頁" + perpageLength + " 字符,調(diào)整字符數(shù):input type='text' value='"+perpageLength+"' id='ctlPerpageLength'input type='button' value='確定' onclick='DHTMLpagenation.change(document.getElementById(\"ctlPerpageLength\").value);'";
divDisplayPagenation.innerHTML=strDisplayPagenation;
}};
DHTMLpagenation.previous=function() { with(this)
{
DHTMLpagenation.goto(currentPage-1);
}};
DHTMLpagenation.next=function() { with(this)
{
DHTMLpagenation.goto(currentPage+1);
}};
DHTMLpagenation.goto=function(iCurrentPage) { with (this)
{
startime=new Date();
if(regularExp.test(iCurrentPage))
{
currentPage=iCurrentPage;
strDisplayContent=content.substr((currentPage-1)*perpageLength,perpageLength);
}
else
{
alert("page parameter error!");
}
DHTMLpagenation.displayPage();
DHTMLpagenation.displayContent();
}};
DHTMLpagenation.displayContent=function() { with (this)
{
divDisplayContent.innerHTML=strDisplayContent;
}};
DHTMLpagenation.change=function(iPerpageLength) { with(this)
{
if(regularExp.test(iPerpageLength))
{
DHTMLpagenation.perpageLength=iPerpageLength;
DHTMLpagenation.currentPage=1;
DHTMLpagenation.initialize();
}
else
{
alert("請(qǐng)輸入數(shù)字");
}
}};
// method
// DHTMLpagenation(strContent,perpageLength)
DHTMLpagenation(s,100);
//--
/script
網(wǎng)站欄目:javascript換頁,js替換整個(gè)頁面
URL網(wǎng)址:http://chinadenli.net/article28/dsgihjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、服務(wù)器托管、靜態(tài)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)