js 清空file 值怎么清空

JavaScript011

js 清空file 值怎么清空,第1张

清空上传控件(<input type="file"/>)的值的两种方法

方法1:

<span id=span1>

<input name=ab type=file>

</span>

<input name=button1 type=button value="按" onclick=show()>

<script language=javascript>

function show()

{

document.getElementById("span1").innerHTML="<input name=ab type=file>"

}

</script>

方法2:

function clearFileInput(file){

var form=document.createElement('form')

document.body.appendChild(form)

//记住file在旧表单中的的位置

var pos=file.nextSibling

form.appendChild(file)

form.reset()

pos.parentNode.insertBefore(file,pos)

document.body.removeChild(form)

}

应该用如下语言清空:

<head>

<script>

function clearDefaultText (el,message)

var obj = el

if(typeof(el) == "string")

obj = document.getElementById(id)

if(obj.value == message)

obj.value = ""

obj.onblur = function()

if(obj.value == "")

obj.value = message

</script>

</head>

<body>

<input type="text" id="searchKey" name="searchKey" value="请输入标题" onclick="clearDefaultText(this,'请输入标题')"/>

</body>

拓展资料

1、JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是HTML(标准通用标记语言下的一个应用)网页上使用,用来给HTML网页增加动态功能。

2、在1995年时,由Netscape公司的Brendan Eich,在网景导航者浏览器上首次设计实现而成。因为Netscape与Sun合作,Netscape管理层希望它外观看起来像Java,因此取名为JavaScript。但实际上它的语法风格与Self及Scheme较为接近。

3、为了取得技术优势,微软推出了JScript,CEnvi推出ScriptEase,与JavaScript同样可在浏览器上运行。为了统一规格,因为JavaScript兼容于ECMA标准,因此也称为ECMAScript。

1.动态页面:index.asp?id=....

2.使用jquery,$.ajaxSetup({cache : false })

3.在html里的head标签中加

<meta http-equiv ="proma" content = "no-cache"/>

<meta http-equiv="cache-control" content="no cache" />

<meta http-equiv="expires" content="0" />

另外一种:

<html http-equiv="proma" content="no-cache"/>

<html http-equiv="content-type" content="no-cache , must-revalidate"/>

<http http-equiv="expires" content=" Wed , 26 Feb 1997 08:21:57 GMT"/>

另外 ,在提交信息时,总是出现旧的内容,此时就应该考虑是本地浏览器缓存的原因了。

清空临时缓存的方法:

<body onload ="javascript : document.yourFormName.reset()">