如何去掉中文字符串首尾空格
yoken 2003-07-04 04:40:09 把下面的代码保存到一个htm文件里,点那个checkbox看看
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
// 选择当前单位
function selectDqdw(field) {
alert("aaa" + " 集团本级".replace(/(^\s*)|(\s*$)/g, "") + "bbb");
if (field.checked) {
alert(/^\s*/g.test(field.parentNode.nextSibling.childNodes[0].nodeValue));
alert("aaa" +
field.parentNode.nextSibling.childNodes[0].nodeValue.replace(
/(^\s*)|(\s*$)/g, ""));
document.all.dqdwdm.value =
field.parentNode.previousSibling.childNodes[0] == null ?
"" : field.parentNode.previousSibling.childNodes[0].nodeValue;
document.all.dqdwmc.value =
field.parentNode.nextSibling.childNodes[0] == null ?
"" : field.parentNode.nextSibling.childNodes[0].nodeValue;
} else {
document.all.dqdwdm.value = "";
document.all.dqdwmc.value = "";
}
}
</script>
</head>
<body bgcolor="#ffffee">
<form name="form1" method="post" action="oaTNbglTNrapTWjmlFpdwTMainAction.jsp">
<input type="hidden" name="dwdm" value="001001">
<table width="400" border="0" align="center">
<tr>
<td><table width="400" border="0">
<tr>
<td width="59">当前文件</td>
<td width="331">
<input name="wjmc" type="text" class="smallInput" value="444444">
</td>
</tr>
</table></td>
</tr>
<tr>
<td> <DIV id="Layer1" style="position:relative;top:-1px;width:350px;height :
250px;z-index:1;overflow-x:hidden;overflow-y:auto" scrolling="Auto">
<table width="400" border="0" cellspacing="1" bgcolor="#0000cc">
<tr id="dw">
<td style="display:none">001001</td>
<td bgcolor="ffffee" width="45" align="center"><input type="checkbox"
name="fpdwBh" value="2" onClick="selectDqdw(this)"></td>
<td bgcolor="ffffee" width="345">
集团本级
</td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td>
<table>
<tr>
<td>当前单位</td>
<td><input type="text" name="dqdwmc" class="smallInput"
readonly>
<input type="hidden" name="dqdwdm"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table width="400" border="0">
<tr>
<td><input name="Submit" type="button" class="buttonface" value="全 选"
onClick="checkAll(document.form1.fpdwBh)"></td>
<td><input name="Submit2" type="button" class="buttonface" value="反 选"
onClick="toggleAll(document.form1.fpdwBh)"></td>
<td><input name="Submit3" type="button" class="buttonface" value="下级全选"
onClick="xjqx()"></td>
<td><input name="Submit4" type="button" class="buttonface" value="下级反选"
onClick="xjfx()"></td>
<td><input name="save" type="submit" class="buttonface" value="保 存"></td>
<td><a href="oaTNbglTNrap.jsp" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image1','','../image/back1.gif',1)" target="_top"><img
name="Image1" border="0" src="../image/back.gif" width="43" height="18"></a></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>