Javascript add a PHP file
var editing = false; if (document.getElementById && document.createElement) { var butt = document.createElement('BUTTON'); var buttext = document.createTextNode('Ready!'); butt.appendChild(buttext); butt.onclick = saveEdit; } function catchIt(e) { if (editing) return; if (!document.getElementById || !document.createElement) return; if (!e) var obj = window.event.srcElement; else var obj = e.target; while (obj.nodeType != 1) { obj = obj.parentNode; } if (obj.tagName == 'TEXTAREA' || obj.tagName == 'A') return; while (obj.nodeName != 'P' && obj.nodeName != 'HTML') { obj = obj.parentNode; } if (obj.nodeName == 'HTML') return; var x = obj.innerHTML; var y = document.createElement('TEXTAREA'); var z = obj.parentNode; z.insertBefore(y,obj); z.insertBefore(butt,obj); z.removeChild(obj); y.value = x; y.focus(); editing = true; } function saveEdit() { var area = document.getElementsByTagName('TEXTAREA')[0]; var y = document.createElement('P'); var z = area.parentNode; y.innerHTML = area.value; z.insertBefore(y,area); z.removeChild(area); z.removeChild(document.getElementsByTagName('button')[0]); editing = false; } document.onclick = catchIt;
此代码是一个快速编辑,我想添加一个PHP脚本,它将更新我的数据库基于文本上的更改。
I suggest studying AJAX.
There are also JavaScript libraries out there that make AJAX easy to use. jQuery is one.
你需要为此使用Ajax。
Javascript works on the client side, so it is not possible to add php script, however you can use ajax for this purpose, from which u can interact with ur database.
For this u had to make a seperate php script and you can call it through your javascript function, which work instantly without reloading the page
链接地址: http://www.djcxy.com/p/53282.html上一篇: 如何让Google Analytics(分析)跟踪幻灯片上的单个图像?
下一篇: Javascript添加一个PHP文件