Ajax+PHP 邊學邊練 之二 執行個體

來源:互聯網
上載者:User

效果1. 當滑鼠放在某日上時,如果當天有備忘錄,則會顯示出來,如:
複製代碼 代碼如下:function checkfortasks (thedate, e){
//找到頁面中taskbox對應<div>設定為可見
theObject = document.getElementById("taskbox");
theObject.style.visibility = "visible";
//初始化taskbox位置
var posx = 0;
var posy = 0;
//定位taskbox位置為滑鼠位置
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
//設定PHP請求頁面
serverPage = "taskchecker.php?thedate=" + thedate;
//設定PHP返回資料替換位置
objID = "taskbox";
var obj = document.getElementById(objID);
//發送請求並載入返回資料
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

效果2. 當滑鼠點擊某日錄入姓名時,系統會自動檢索姓名是否存在,並可以通過選擇填入姓名框中,
複製代碼 代碼如下:function autocomplete (thevalue, e){
//定位頁面中autocompletediv(顯示檢索姓名的標籤)的<div>位置
theObject = document.getElementById("autocompletediv");
//設定為可見
theObject.style.visibility = "visible";
theObject.style.width = "152px";
//設定檢索標籤位置
var posx = 0;
var posy = 0;

posx = (findPosX (document.getElementById("yourname")) + 1);
posy = (findPosY (document.getElementById("yourname")) + 23);

theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
//設定事件為鍵盤錄入
var theextrachar = e.which;

if (theextrachar == undefined){
theextrachar = e.keyCode;
}
//設定載入檢索名單位置
var objID = "autocompletediv";

//設定PHP請求頁面,並將使用者輸入的姓名傳值過去(同時考慮到Backspace作用)
if (theextrachar == 8){
if (thevalue.length == 1){
var serverPage = "autocomp.php";
}
else{
var serverPage = "autocomp.php" + "?sstring=" + thevalue.substr(0, (thevalue.length -1));
}
}
else{
var serverPage = "autocomp.php" + "?sstring=" + thevalue + String.fromCharCode(theextrachar);
}
//發送請求並載入返回資料
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

檔案打包下載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.