javascript void 0提取问题!

碰到个非常头疼的问题。
&script Language="JavaScript"&
function change()
document.form1.pic.src=document.form1.file1.
&form name="form1"
enctype="multipart/form-data"&
&td& 草图:&/td&
&input type="file" name="file1"
onchange="javascript:change()"&
&td&草图浏览:&/td&
&img src="images/px.gif"
name="pic"
当点击浏览文件的时候,草图浏览会显示当前选择的图片。
很简单的一个功能,但是现在的问题是,这段代码在IE6工作正常,IE7,IE8完全没有反应。
还请多多指教。
------------------------------------------------------------------------------------------------------------------
问题补充:
kjah 写道&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&
&html xmlns="http://www.w3.org/1999/xhtml"&
&head&
&script Language="JavaScript"&
& function change(){
& var pic=document.getElementById("pic");
& var file=document.getElementById("file1");
&&&&& pic.src=file.
& if(file.files){
if(file.files.item(0)){
url=file.files.item(0).getAsDataURL();
& }
& }
&/script&
&body&
&form name="form1"& enctype="multipart/form-data"&
&&&&&&&&& &td& 草图:&/td&
&&&&&&&&& &td &
&
&&& &input type="file" name="file1" id="file1"& onchange="change()"&
&tr&
&&&&&&&&& &td&草图浏览:&/td&
&&&&&&&&& &td&
&
&&& &img src="images/px.gif"& name="pic" id="pic" &
& &/td&
&&&&&&&
&/body&
&/html&
刚使用了大哥的这段代码,仍然不行,经过查证发现。我原来的代码如果保存为html文件在本地IE6.7.8打开没有任何问题,问题出在,当我放到服务器端时,只有IE6才能出现出现我想要的效果。服务器端页面为jsp页面。求解。
问题补充:碰到个非常头疼的问题。
&script Language="JavaScript"&
function change()
document.form1.pic.src=document.form1.file1.
&form name="form1"
enctype="multipart/form-data"&
&td& 草图:&/td&
&input type="file" name="file1"
onchange="javascript:change()"&
&td&草图浏览:&/td&
&img src="images/px.gif"
name="pic"
当点击浏览文件的时候,草图浏览会显示当前选择的图片。
很简单的一个功能,但是现在的问题是,这段代码在IE6工作正常,IE7,IE8完全没有反应。
还请多多指教。
------------------------------------------------------------------------------------------------------------------
问题补充:
kjah 写道&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&
&html xmlns="http://www.w3.org/1999/xhtml"&
&head&
&script Language="JavaScript"&
& function change(){
& var pic=document.getElementById("pic");
& var file=document.getElementById("file1");
&&&&& pic.src=file.
& if(file.files){
if(file.files.item(0)){
url=file.files.item(0).getAsDataURL();
& }
& }
&/script&
&body&
&form name="form1"& enctype="multipart/form-data"&
&&&&&&&&& &td& 草图:&/td&
&&&&&&&&& &td &
&
&&& &input type="file" name="file1" id="file1"& onchange="change()"&
&tr&
&&&&&&&&& &td&草图浏览:&/td&
&&&&&&&&& &td&
&
&&& &img src="images/px.gif"& name="pic" id="pic" &
& &/td&
&&&&&&&
&/body&
&/html&
刚使用了大哥的这段代码,仍然不行,经过查证发现。我原来的代码如果保存为html文件在本地IE6.7.8打开没有任何问题,问题出在,当我放到服务器端时,只有IE6才能出现出现我想要的效果。服务器端页面为jsp页面。求解。
采纳的答案
浏览器的安全策略不允许JS访问上传文件的路径,只能取得文件名。
IE8下获取的路径还会是个假的,好像是“C:\fakepath\xxx.xxx”
并且在IE7以上版本不能在非本地域时设置src为本地路径
不过网上有很多特殊方法来实现,IE用选中区域文字获取路径,滤镜显示图片。
FF直接获取base64编码后的文件
还可以用ActiveX来做这个功能,或者依靠服务器实现。(上传到服务器,再从服务器请求缩略图。。。)
这里有最详细的一篇文章:
&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&
&html xmlns="http://www.w3.org/1999/xhtml"&
&head&
&script Language="JavaScript"&
& function change(){
& var pic=document.getElementById("pic");
& var file=document.getElementById("file1");
&&&&& pic.src=file.
& if(file.files){
if(file.files.item(0)){
url=file.files.item(0).getAsDataURL();
& }
& }
&/script&
&body&
&form name="form1"& enctype="multipart/form-data"&
&&&&&&&&& &td& 草图:&/td&
&&&&&&&&& &td &
&
&&& &input type="file" name="file1" id="file1"& onchange="change()"&
&tr&
&&&&&&&&& &td&草图浏览:&/td&
&&&&&&&&& &td&
&
&&& &img src="images/px.gif"& name="pic" id="pic" &
& &/td&
&&&&&&&
&/body&
&/html&
已解决问题
未解决问题javascript获取ID的问题_百度知道
提问者采纳
&script&type=&text/javascript&&function&Req(obj){&&&&alert(obj.getAttribute(&id&));}&/script&&h1&id='f2'&onclick='Req(this)'&问题&/h1&&h1&id='f1'&onclick='Req(this)'&问题&/h1&如果你是想取ID里面的f1& f2 上面的代码 就取得了。&script&type=&text/javascript&&function&Req(obj){&&&&obj.innerHTML&=&&求解决&;}&/script&&h1&id='f2&#3哗担糕杆蕹访革诗宫涧9;&onclick='Req(this)'&问题&/h1&&h1&id='f1'&onclick='Req(this)'&问题&/h1&或者你是需要这样。
我的那段代码为什么不行呢?
因为你的function 里面的 this 是指向那个方法本身的,而不是你的点击元素。所以你看上去没有变化,则不是代码没执行。而我把this 写在了 h1 里面了。这个时候 this 代表的就是 h1 这个元素,那么传过去之后,obj就是指向这个元素的,这时候对这个元素进行操作,则会有效果。不知道这样讲你明白没。
提问者评价
其他类似问题
&html&&head&&script&function req(obj){obj.innerHTML='qqq';}&/script&&/head&&body&&h1 id='哗担糕杆蕹访革诗宫涧f2' onclick=&req(this)&&question&/h1&&h1 id='f1' onclick=&req(this)&&question&/h1&&/body&&/html&
按默认排序
其他3条回答
&html&&meta http-equiv=&Content-Type& content=&text/ charset=utf-8& /&&head&&script type=&text/javascript& src=&&&&/script&&/head&&script&function req(obj){ alert($(obj).attr('id'));}&/script&&body&&h1 id='f2' onclick=&req(this)&&question&/h1&&h1 id='哗担糕杆蕹访革诗宫涧f1' onclick=&req(this)&&question&/h1&&/body&&/html&
原生方法 return this.getAttribute(&id&)
document.getEletmentById(&f2&);
javascript的相关知识
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁JavaScript获取文本框内选中的文本
0人收藏此代码,
这段代码可以用来获取用户通过鼠标在文本输入框或者textarea里选择的选本。
需要注意ie的问题
注:当在IE里使用非按钮的元素onclick触发事件的时候,会得不到结果。因为在IE里,当一个非按钮元素被click,整个页面中的选择内容将会被改变。而在firefox,opera下就不存在这个问题。所以上面的(Span_onclick)在IE下将不可用
代码如下:
&script type=&text/javascript&&
function getFieldSelection(select_field)
word='';
if (document.selection) {
var sel = document.selection.createRange();
if (sel.text.length & 0) {
word = sel.
else if (select_field.selectionStart || select_field.selectionStart == '0') {
var startP = select_field.selectionS
var endP = select_field.selectionE
if (startP != endP) {
word = select_field.value.substring(startP, endP);
&textarea id=&a& rows=&3& cols=&20&&选择我,然后点击下面的按钮&/textarea&&br /&
&button onclick=&alert(getFieldSelection(document.getElementById('a')))&&button_click&/button&
//该代码片段来自于: /codes/javascript/9008
注:当在IE里使用非按钮的元素onclick触发事件的时候,会得不到结果。因为在IE里,当一个非按钮元素被click,整个页面中的选择内容将会被改变。而在firefox,opera下就不存在这个问题。所以上面的(Span_onclick)在IE下将不可用
相关代码片段:
最新JavaScript代码片段
合作网站:Javascript获取客户端IP和Mac的问题
[问题点数:100分,结帖人gch_519]
Javascript获取客户端IP和Mac的问题
[问题点数:100分,结帖人gch_519]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。关于javascript获取当前对象的问题
[问题点数:20分,结帖人t]
关于javascript获取当前对象的问题
[问题点数:20分,结帖人t]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 javascript跨域问题 的文章

 

随机推荐