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

请教:如何提取文本框中选定的字符
一个文本框中的字符串
例如:2007-08-16
一段Javascript代码
去掉中间的“-”
得出20070816
将其赋值给另外一个文本框

------解决方案--------------------
<html>

<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 新建网页 2 </title>
</head>
<script language= "javascript ">
function cli()
{
var xx = document.ax.a.value;
var aaa = xx.split( "- ");
var bb= " ";
for(var i=0; i <aaa.length; i++)
bb += aaa[i];
document.ax.b.value = bb;
}
</script>
<body>
<form name= "ax ">
<input type= "text " name= "a " value= "2007-08-16 ">
<input type= "button " onclick= "cli() ">
<input type= "text " name= "b ">
</form>
</body>

</html>

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>

<BODY>
<script language= "javascript ">
function _trim(){
var aText = document.all.a.value;
aText = aText.replace(new RegExp( "- ", "gm "), " ");
//alert(aText);
document.all.b.value = aText;
}
</script>

<input type= "text " name= "a " value= "2007-8-16 " />
<input type= "text " name= "b " />
<input type= "button " value= "Go " onclick= "_trim() " />
</BODY>
</HTML>