<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
//单击变为文本框function changeToInput(id) {
alert("进入了");
var oNP = document.getElementById(id);
var value;
if(navigator.appName=="Microsoft Internet Explorer"){
value=oNP.value;
} else {
value= oNP.textContent;
}
//alert("value="+value);
oNP.innerHTML = "<div value='"+value+"'><input type='text' id='" + id + "' value='" + value + "' size='1' onblur='change(this.id,\""+str+"\")'></div>";
//oNP.outerHTML = "<div class="+str+" value='"+value+"'></div>";
document.getElementById(id).focus();
//document.getElementById(id).select();
}
function change(id,str) {
var oNP = document.getElementById(id);
var value=oNP.value;
oNP.innerHTML = "<div id='" + id + "' value='" + value + "' onclick='changeToInput(this.id,\""+str+"\")'><b>" + value + "</b></div>";
}
</script>
</head>
<body>
<div id="ss" onclick="changeToInput(this.id)" value="3">3</div>
<script language="javascript">
var str=document.getElementById("ss");
var mm;
if(navigator.appName=="Microsoft Internet Explorer")
mm=str.value;
else
mm=str.textContent;
alert(mm);
</script></body>
</html>
这是我的代码,请问有什么好的解决方法
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
//单击变为文本框function changeToInput(id) {
alert("进入了");
var oNP = document.getElementById(id);
var value;
if(navigator.appName=="Microsoft Internet Explorer"){
value=oNP.value;
} else {
value= oNP.textContent;
}
//alert("value="+value);
oNP.innerHTML = "<div value='"+value+"'><input type='text' id='" + id + "' value='" + value + "' size='1' onblur='change(this.id,\""+str+"\")'></div>";
//oNP.outerHTML = "<div class="+str+" value='"+value+"'></div>";
document.getElementById(id).focus();
//document.getElementById(id).select();
}
function change(id,str) {
var oNP = document.getElementById(id);
var value=oNP.value;
oNP.innerHTML = "<div id='" + id + "' value='" + value + "' onclick='changeToInput(this.id,\""+str+"\")'><b>" + value + "</b></div>";
}
</script>
</head>
<body>
<div id="ss" onclick="changeToInput(this.id)" value="3">3</div>
<script language="javascript">
var str=document.getElementById("ss");
var mm;
if(navigator.appName=="Microsoft Internet Explorer")
mm=str.value;
else
mm=str.textContent;
alert(mm);
</script></body>
</html>
这是我的代码,请问有什么好的解决方法
str 是一个html的div ,这样字符串了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
//单击变为文本框
function changeToInput(id) {
//alert("进入了");
var oNP = document.getElementById(id);
var value;
if(navigator.appName=="Microsoft Internet Explorer"){
value=oNP.value;
} else {
value= oNP.getAttribute("value");
}
var str=document.getElementById("ss");
//alert("value="+value);
oNP.innerHTML = "<div value='"+value+"'><input type='text' id='" + id + "' value='" + value + "' size='1' onblur='change(this.id,\""+str+"\")'></div>";
//oNP.outerHTML = "<div class="+str+" value='"+value+"'></div>";
//document.getElementById(id).focus();
//document.getElementById(id).select();
}function change(id,str) {
var oNP = document.getElementById(id);
var value=oNP.value || oNP.getAttribute("value");
//alert("value="+value);
oNP.innerHTML = "<div id='" + id + "' value='" + value + "' onclick='changeToInput(this.id,\""+str+"\")'><b>" + value + "</b></div>";}
</script>
</head>
<body>
<div id="ss" onclick="changeToInput(this.id)" value="3">3</div>
<script language="javascript">
/*var str=document.getElementById("ss");
var mm;
if(navigator.appName=="Microsoft Internet Explorer")
mm=str.value;
else
mm=str.textContent;*/
//alert(mm);
</script></body>
</html>现在ff和ie是一样的效果