|
±¾ÆªÍ¨¹ýÒ»¸öʵÀý½éÉÜAjaxÓëPHP½áºÏʹÓõķ½Ê½£¬¿ÉÒÔÏÂÔظÃʵÀýµÄÔ´³ÌÐòÒÔ±ã¸üºÃÀí½â¡£Ñ¹Ëõ°üÖÐfunctions.js¾ÍÊÇAjaxºËÐÄ´úÂëÁË£¬ËùÓеIJÙ×÷Ч¹û¶¼ÊÇͨ¹ýËüÀ´ÊµÏֵġ£ÏÂÎĵĴúÂë½âÊͶ¼ÊÇÌáÈ¡×Ôfunctions.js¡£
Ч¹û1. µ±Êó±ê·ÅÔÚijÈÕÉÏʱ£¬Èç¹ûµ±ÌìÓб¸Íü¼£¬Ôò»áÏÔʾ³öÀ´£¬ÈçÏÂͼ£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ: 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. µ±Êó±êµã»÷ijÈÕ¼ÈëÐÕÃûʱ£¬ÏµÍ³»á×Ô¶¯¼ìË÷ÐÕÃûÊÇ·ñ´æÔÚ£¬²¢¿ÉÒÔͨ¹ýÑ¡ÔñÌîÈëÐÕÃû¿òÖУ¬Èçͼ£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ: 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); }
Îļþ´ò°üÏÂÔØ |
|