js 의 각종 사용자 정의 함수
function trim(inputString) {
if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") {
//
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") {
//
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) {
//
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length);
}
return retValue;
}
2. js 팝 업 알림 층, 그리고 페이지 잠 금
<body>
<a href="PAGE/MyJsp.jsp">This a struts page.</a> <br>
<input type="button" value=" " onclick="sAlert('test ');" />
</body>
</html:html>
<script type="text/javascript" language="javascript">
//more javascript from http://www.smallrain.net
function sAlert(str){
var msgw,msgh,bordercolor;
msgw=400;//
msgh=100;//
titleheight=25 //
bordercolor="#c51100";//
titlecolor="#c51100";//
var sWidth,sHeight;
sWidth=screen.width;
sHeight=screen.height;
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#cccccc";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
var title=document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.innerHTML=" ";
title.onclick=function(){
document.body.removeChild(bgObj);
document.getElementById("msgDiv").removeChild(title);
document.body.removeChild(msgObj);
}
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(title);
var txt=document.createElement("p");
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.innerHTML=str;
document.getElementById("msgDiv").appendChild(txt);
}
</script>
3. js 의 날짜 처리
function cc(dd,dadd)
{
//
var a = new Date(dd)
a = a.valueOf()
a = a +dadd * 24 * 60 * 60 * 1000
a = new Date(a)
return (a.getFullYear() + "-" + (a.getMonth() + 1) + "-" + a.getDate() )
}
//
function mapOnClick()
{
var string = (document.form1.endtime.value).split("-");
var string2 = (document.form1.endtime2.value).split("-");
// alert(new Date());
var myDate = new Date(string[0],string[1]-1,string[2]);
var myDate2 = new Date(string2[0],string2[1]-1,string2[2]);
//
var newYear=new Date().getYear();
var newMonth=new Date().getMonth();
if(newMonth==12){
newMonth=1;
}else{
newMonth=newMonth+1;
}
var newDay=new Date().getDate();
if(myDate2>new Date()){
//alert(newYear+"-"+newMonth+"-"+newDay);
document.form1.endtime2.value=newYear+"-"+newMonth+"-"+newDay;
}
if(myDate>new Date()){
//alert(newYear+"-"+newMonth+"-"+newDay);
document.form1.endtime.value=newYear+"-"+newMonth+"-"+newDay;
}
if(myDate2<myDate){
alert(" , !");
return flase;
}
//alert(document.form1.endtime.value);
//var myDate = new Date(document.form1.endtime.value);
//alert(myDate);
//
if(Date.parse(myDate2)==Date.parse(myDate)){
myDate=cc(myDate,1);
//alert(myDate);
// myDate.setDate(myDate.getDate()+1)
document.form1.endtime2.value=myDate;
}
form1.map.value = "1";
form1.table1.value = "2";
if( form1.endtime.value == "" || form1.endtime2.value == "" )
{
alert(" , !");
return;
}
form1.submit();
}
////////////////////////////////////////
try{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date=dateFormat.parse(begin);
long dateMS = date.getTime();
dateMS = dateMS + 60 * 60 * 24 * 1000 * 1;
date.setTime(dateMS);
String dateString = dateFormat.format(date);
end=dateString;
//System.out.println("date:::"+dateString);
}catch(Exception e){
e.printStackTrace();
}
4. 모든 폼 항목 이 비어 있 지 않 음 을 판단 합 니 다.
function checkdate() {
//alert("sadfsa");
var input = document.all.tags("input");
for(i=0;i<input.length;i++)
{
if (trimString(input[i].value)=="")
{
alert(" !");
return false;
}
}
5. 페이지 지정 시간 후 자동 으로 이동
<body>
<!-- url -->
<meta http-equiv="Refresh" content="5;url= ">
<table>
<tr>
<td width="181" height="30" class="FontBlack"> </td>
<td width="22" align="center" class="FontBlack"><div id="time">5</div></td>
<td width="194" align="left" class="FontBlack"> </td>
</tr>
</table>
</body>
<script language="JavaScript">
var times=6;
clock();
function clock()
{
window.setTimeout('clock()',1000);
times=times-1;
time.innerHTML =times;
}
</script>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
기초 정리 - 1문자 (String) 숫자 (Number) 불린 (Boolean) null undefined 심볼 (Symbol) 큰정수 (BigInt) 따옴표로 묶어 있어야 함 Not-A-Number - 숫자 데이터 / 숫자로 표...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.