JavaScript 判断文件是否存在
1. 客户端 //主要针对本地IE浏览器访问
<script
language="javascript">
function FileExist()
{
var sfso=new
ActiveXObject("Scripting.FileSystemObject");
var fPath="[The path of the
file]";
if(sfso.FileExists(fPath))
{
alert("Exist");
}
else
{
alert("Doesn't
exist");
}
}
</script>
2.
服务器端//远程浏览器访问和本地Firefox访问
<script
language="javascript">
function FileExist()
{
var xmlhttp=new
ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET",FileURL,false);
xmlhttp.send();
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
alert("Exist");
else if(xmlhttp.status==404) alert("Doesn't
exist");
else alert("Don't know");
}
}
</script>
或者
<script language="JavaScript">
function fileExists(file)
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject)
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
 
相关文档:
每一项都是js中的小技巧,但十分的实用!
1.document.write(""); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的 ......
简单的例子,自己看看,省得以后老是去找了。
<script language="javascript">
//用正则替换将X替换成y
var s="daxdasx";//原字符串
var k="x";//被替换的字段
var re = new RegExp(k,"g");
alert("替换前字符串为:"+s);
s = s.replace(re,"y");
alert("替换后字符串为:"+s);
</script> ......
在javascript中获取中英文字符长度的问题
var i="中国a";
一般情况下,我们用i.length会得到结果3
但有时候我们需要5,下面的小代码可以解决问题
Java代码
1. <script>
2. alert (fucCheckLength("中国aaaa"));
& ......
原文出处: http://www.dnew.cn/post/196.htm
先看下下面几种写法
1.function f(x){return x*x;};f(x);
2.(function(x){return x*x;})(x);
3.(function(x){return x*x;}(x));
第一种我们应该都很熟悉了,这是我们经常使用的写法。第二第三种都是匿名函数的写法。
------------------------------------------------ ......