论坛首页 Web前端技术论坛

JavaScript实现Label标签的赋值操作

浏览 4495 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-08-06   最后修改:2012-08-15
<!DOCTYPE html>
<meta charset="utf-8">
<head>
	<title>File Input</title>
</head>
<body>
	<fieldset>
		<legend>文件上传</legend>
		
		<input type="file" name="uploadfile" id="upfile" />
		<input type="button" name="bupfile" value="读取文件内容" onclick="readFile();" />
		<label id="content" >path</label>
	</fieldset>
	
	<script>
		function readFile() {
			
			var filePath = document.getElementById("upfile").value;
			document.getElementById("content").innerHTML = filePath;
			//document.getElementById("content").innerText = filePath;
		}
	</script>
</body>

本人最近在学习JavaScript,在学习过程中,发现了这样一个问题,如上的代码,document.getElementById("content").innerHTML = filePath;这条语句在firefox,IE,googl的chrome的浏览器中都可以正常进行赋值操作,但是在firefox只能获得文件名,在另外两个浏览器中都能显示临时路径。
document.getElementById("content").innerText = filePath;这条语句在firefox下却不起作用,另外两个浏览器却可以正常使用,且都显示临时路径。
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics