日期:2014-05-16 浏览次数:20652 次
调用代码
<span id="1" onclick="changeToInput(this.id)" value="hello"> hello </span>
?
?
javascript实现代码如下
??????
<script type="text/javascript"> var req; var gID; function changeToInput(id) {// var oNP = document.getElementById(id); var value = oNP.value; oNP.outerHTML = "<input type='text' id='" + id + "' value='" + value + "' size='5' onblur='change(this.id)'>"; document.getElementById(id).focus(); } function change(id) { var oNP = document.getElementById(id); var value = oNP.value; gID = id; init(); var url = "ChangePrice.jsp?id=" + escape(id) + "&normalprice=" + value; req.open("GET", url, true); req.onreadystatechange = callback; req.send(null); } function init() { if(window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } } function callback() { if(4 == req.readyState) { if(200 == req.status) { var oNP = document.getElementById(gID); var value = oNP.value; oNP.outerHTML = "<span style='background:gray' id='" + gID + "' value='" + value + "' onclick='changeToInput(this.id)'>" + value + "</span>"; } } } </script>
?