方法一楼上: 或者<script language="javascript"> function XmlPost2(webFileUrl) { var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); xmlHttp.open("POST", webFileUrl, false); xmlHttp.send(""); var result = /<[^>]+>[\s]*(\d*)/.exec(xmlHttp.responseText)[1]; document.write(parseInt(result,10)*2); } </script>
alert(result)//但关键你这个result要有内容啊
document.write(result*2);//这里 *2就自动转换了。
如果还是NaN,那证明你的responseText 里面是"12355678\n"这样含有其他隐藏字符的串,所以才NaN的。检查你的后台是怎么输出的
<META HTTP-EQUIV="Conten-Type" CONTENT="text/html; charset=gb2312">
55
这个怎么可以过滤掉?
把那句HTML代码改成
<%
response.charset="gb2312"
'.....后台处理
%>
<META HTTP-EQUIV="Conten-Type" CONTENT="text/html; charset=gb2312">
55如果都是这种类型的 可以用正则匹配 “>” 之后的数字
或者<script language="javascript">
function XmlPost2(webFileUrl)
{
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
var result = /<[^>]+>[\s]*(\d*)/.exec(xmlHttp.responseText)[1];
document.write(parseInt(result,10)*2);
}
</script>