下面的代码,哪里错了?为什么用字符串就可以输出正确的值,用object.value输出的就错了呢?
<html>
<head><title>test</title></head>
<body>
<input type="text" value="" id="xxx" />
<input type="button" value="click" onclick="reg()" />
<script type="text/javascript">
function reg() {
var x = document.getElementById('xxx');
alert("\t".replace(/\t/g,"\\\\t"));
alert((x.value).replace(/\t/g,"\\\\t"));
alert((x.value+"").replace(/\t/g,"\\\\t"));
}
</script>
</body>
</html>
<html>
<head><title>test</title></head>
<body>
<input type="text" value="" id="xxx" />
<input type="button" value="click" onclick="reg()" />
<script type="text/javascript">
function reg() {
var x = document.getElementById('xxx');
alert("\t".replace(/\t/g,"\\\\t"));
alert((x.value).replace(/\t/g,"\\\\t"));
alert((x.value+"").replace(/\t/g,"\\\\t"));
}
</script>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货