存档

‘JavaScript’ 分类的存档

JavaScript转换时间格式

2010年7月24日 没有评论

/*将2010-1-6 19:8:2的时间格式转换成2010-01-06 19:08:02的时间格式*/
function getFormat(timeformat){
if(String(timeformat).length == 1){
timeformat = “0″ + String(timeformat);
}
return timeformat;
}

分类: JavaScript 标签:

jQuery实现Ajax的简单示例

2010年6月19日 没有评论

function weblogin(){
var email = $(‘#reg_email’).val().replace(/\s/g,”");
var psw = $(‘#reg_psw’).val().replace(/\s/g,”");
var remember = $(“#remember”).attr(“checked”);
$.ajax(
{
type: “POST”,
url: ajaxBaseUrl + “/Public/doAjaxLogin”,
processData: false,
timeout: 20000,
error: function(){alert(“unknow error”);},
data: “login_email=” + email + “&login_psw=” + psw + “&remember=” + remember ,
success: function(msg)
{
if(msg.indexOf(“SUCCESS”)>=0){
document.getElementById(“btn_login”).disabled = “”;
}
}
}
);
}

分类: JavaScript 标签: ,

JavaScript实现Ajax的简单示例

2010年6月19日 没有评论

<?php
if($_GET){
for($i=0; $i<10; $i++){
echo $_GET["id"];
}
exit;
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Ajax</title>
<script type=”text/javascript”>
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(url){
createXMLHttpRequest();
xmlHttp.open(“GET”, “?id=” + url, true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
document.getElementById(“result”).innerHTML = xmlHttp.responseText;
}
}
xmlHttp.send(null);
}
</script>
</head>

<body>
<a href=”javascript:startRequest(‘o’);”>o</a>
<a href=”javascript:startRequest(‘f’);”>f</a>
<div id=”result”></div>
</body>
</html>

分类: JavaScript 标签: ,

JavaScript获取当前页URL

2010年4月27日 没有评论

var pageUrl = window.location.toString();

pageUrl即为当前页面的URL

分类: JavaScript 标签: ,

javascript自动关闭窗口代码

2010年3月18日 没有评论

<script language=”javascript”>
<!–
function clock(){i=i-1
document.title=i+”秒后本内容将关闭!”;
if(i>0)setTimeout(“clock();”,1000);
else self.close();}
var i=120
clock();
//–>
</script>

分类: JavaScript 标签:

setInterval() – JavaScript定时发出请求

2010年2月8日 没有评论

timer_runting  =  setInterval(“CheckMsgs();”,30000);

function CheckMsgs(){
……
}

分类: JavaScript 标签:

JavaScript设置过几秒钟后div自动消失

2010年1月27日 没有评论

setTimeout(“document.getElementById(‘result’).style.display = ‘none’;”, 3600);

分类: JavaScript 标签:

JavaScript改变父窗口中的元素

2010年1月27日 没有评论

window.parent.document.getElementById(“defalut_loading_module”).style.display = “none”

分类: JavaScript 标签:

JavaScript获取系统时间并格式化为’Y-m-d H:i:s’的格式

2010年1月27日 没有评论

function getFormat(timeformat){
if(String(timeformat).length == 1){
timeformat = “0″ + String(timeformat);
}
return timeformat;
}
var thetime = new Date();
document.write(getFormat(thetime.getFullYear()) + “-” + getFormat(thetime.getMonth()+1) + “-” + getFormat(thetime.getDate()) + ” ” + getFormat(thetime.getHours()) + “:” + getFormat(thetime.getMinutes()) + “:” + getFormat(thetime.getSeconds()));

分类: JavaScript 标签: ,

JavaScript将服务器端时间转换成客户端时间

2010年1月25日 没有评论

<script type=”text/javascript”>
/////////////////////////////////////////////////
// 将2010-1-6 19:8:2的时间格式转换成2010-01-06 19:08:02的时间格式
// curdate:需要转换的时间
// ismonth:是否是月份,因为月份要加1
/////////////////////////////////////////////////
function getRealDate(curdate, ismonth){
if(ismonth){
curdate++;
}
if(String(curdate).length == 1){
curdate = “0″ + String(curdate);
}
return curdate;
}
</script>

<script language=”javascript” type=”text/javascript”>
/////////////////////////////////////////////////
// 将服务器时间转换成客户端时间(服务器用GMT时间)
// sourcetime:需要转换的时间,格式为2010-01-06 19:08:02
// nohis:是否需要时分秒,如果有则不需要
/////////////////////////////////////////////////
function toLocalTime(sourcetime, nohis){
var sourcetime = sourcetime.replace(/:/g, ‘-’);
var sourcetime = sourcetime.replace(/ /g, ‘-’);
var arr = sourcetime.split(“-”);//将时间格式化
var temptime = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3],arr[4],arr[5]));
var timestamp = temptime.getTime();//转换成时间戳
var temp = new Date(timestamp);
if(nohis){
var newtime = temp.getFullYear() + “-” + getRealDate(temp.getMonth(), 1) + “-” + getRealDate(temp.getDate());
}else{
var newtime = temp.getFullYear() + “-” + getRealDate(temp.getMonth(), 1) + “-” + getRealDate(temp.getDate()) + ” ” + getRealDate(temp.getHours()) + “:” + getRealDate(temp.getMinutes()) + “:” + getRealDate(temp.getSeconds());
}
return newtime;
}
var str = ’2010-01-06 19:08:02′;
document.write(“服务器端时间:” + str + “<br />客户端时间:” + toLocalTime(str));
</script>

分类: JavaScript 标签: