日期:2014-05-16  浏览次数:20398 次

清除文本框中的字符串???
<html>
<body>

<script type="text/javascript">
function delete(){
var str=content.text1.value;
str=str.replace("content.text1.value","");
content.text1.value=str;
}
</script>
<form name="content" method="post" action="">
<input name = "compare" type = "button" value = "compare" onclick = "delete()"/>
<input name = "text1" type = "text" size = "10" value = "enter"/>
</body>
</html>


请帮忙看下这个程序错在哪儿了,或者,写一个怎样的程序来清除文本框中的字符串?
谢谢!

------解决方案--------------------
为何用 replace, 直接 document.content.text1.value="" 不行吗?
HTML code

<html>
<body>

<script type="text/javascript">
function del(){
    var str = document.content.text1.value;
    str=str.replace(document.content.text1.value,"");
    document.content.text1.value=str;
}
</script>
<form name="content" method="post" action="">
<input name = "compare" type = "button" value = "compare" onclick = "del()"/>
<input name = "text1" type = "text" size = "10" value = "enter"/>
</body>
</html>

------解决方案--------------------
HTML code

<!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>
</head>

<body>
<script type="text/javascript">
function deleteValue(){
document.getElementById("text1").value = "";
}
</script>
<form name="content" method="post" action="">
<input name = "compare" type = "button" value = "compare" onclick = "deleteValue()"/>
<input name = "text1" type = "text" size = "10" value = "enter" id="text1"/>
</body>
</html>

delete是保留字,不能用做函数名的