div可编辑 enter或离开焦点后提交数据

2024-02-15 17:46:01 举报文章
<div id="list{$rs['aid']}" contenteditable="true" onblur="postlist('$rs[aid]')" onkeydown="if(window.event.keyCode == 13){event.cancelBubble=true;event.preventDefault();event.stopPropagation();postlist('$rs[aid]')}">{$rs['list']}</div>
function postlist(aid) {
		var xhr = new XMLHttpRequest();
		xhr.open('POST', '?qzurl=$qzurl&dirname=$dirname&file=$file&action=edit_list' );
		xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xhr.send('aid='+aid+'&list='+document.getElementById("list"+aid).innerText);
		xhr.onreadystatechange = function () {
			if (xhr.readyState == 4 && xhr.status == 200) {
				if(xhr.responseText=='ok'){
					location.reload();
				}
			}
		};
	}
如果你认为本文可读性较差,内容错误,或者文章排版错乱,请点击举报文章按钮,我们会立即处理!