Mozilla上的Javascript?在IE上工作。 [英] Javascript on Mozilla? working on IE.

查看:49
本文介绍了Mozilla上的Javascript?在IE上工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我有以下的javascript。它在使用IE6时工作..但是当我使用mozilla 1.0.1时它根本不起作用..


< SCRIPT language =" JavaScript">

var upload_number = 2; function addFileInput()

{

if(upload_number> 10)

{alert(''你一次只能上传10个文件' );

return;}

var moreuploads = document.getElementById(" moreuploads");

var d = document.createElement(" td");

d.style.fontWeight =''bold'';

var file = document.createElement(" input");

var txt1 = document.createTextNode(''文件名:'');

var txt2 = document.createTextNode(''Location:'');

var name = document.createElement(" input");

file.setAttribute(" type"," file");

file.setAttribute(" name"," datafile" + upload_number);

file.setAttribute(" size"," 25");

file.attachEvent(" onchange",checkfilename2);

name.setAttribute(" type"," text");

name.setAttribute(" name"," fname" + upload_number);

name.setAttribute(" id"," fname" + upload_number);

name.setAttribute(" size"," 10");

d.appendChild(txt1);

d.appendChild(name);

d.appendChild(txt2);

d.appendChild(file);

moreuploads.appendChild(d);

upload_number ++;

}


任何想法???

Hi.. i got the following javascript. Its working when using IE6.. but when i use mozilla 1.0.1 it does not work at all..

<SCRIPT language="JavaScript">
var upload_number=2; function addFileInput()
{
if(upload_number>10)
{alert(''You can only upload 10 files at one time'');
return;}
var moreuploads=document.getElementById("moreuploads") ;
var d=document.createElement("td");
d.style.fontWeight=''bold'';
var file=document.createElement("input");
var txt1=document.createTextNode('' File name: '');
var txt2=document.createTextNode('' Location: '');
var name=document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "datafile"+upload_number);
file.setAttribute("size", "25");
file.attachEvent("onchange",checkfilename2);
name.setAttribute("type", "text");
name.setAttribute("name", "fname"+upload_number);
name.setAttribute("id", "fname"+upload_number);
name.setAttribute("size", "10");
d.appendChild(txt1);
d.appendChild(name);
d.appendChild(txt2);
d.appendChild(file);
moreuploads.appendChild(d);
upload_number++;
}

Any idea???

推荐答案

hi ...


attachEvent-method是特定于IE的,所有其他浏览器都使用addEventListener ...所以你必须在浏览器之间有所不同......你可以向窗口询问方法:

hi ...

the attachEvent-method is IE-specific, all other browsers use addEventListener instead ... so you have to differ between browsers ... you may ask the window for the method:

展开 | 选择 | Wrap | 行号



hi ...


attachEvent-method是特定于IE的,所有其他浏览器都使用addEventListener ...所以你必须区别于br owsers ...你可以向窗口询问方法:

hi ...

the attachEvent-method is IE-specific, all other browsers use addEventListener instead ... so you have to differ between browsers ... you may ask the window for the method:

展开 | 选择 | Wrap | 行号



嗨...


有效...谢谢......


我又遇到了另一个问题..以下函数也不适用于mozilla ...


函数checkfilename2()

{

var p = event.srcElement;

var n = p.name;

var num = n.substr(8);

var path = p.value;

var fname = path.substring(path.lastIndexOf(" \\\ /")+ 1);

var filename = document.getElementById(''fname''+ num);

if(fname.indexOf(" \ /")> -1)

{

filename.value ="英寸;警告(文件名中不允许使用'/''字符!请指定其他文件名。);

}

其他

filename.value = fname;

}


有什么想法吗?
Hi...

that works... thanks...

I got another problem.. the following function doesnt work on mozilla too...

function checkfilename2()
{
var p=event.srcElement;
var n=p.name;
var num=n.substr(8);
var path=p.value;
var fname=path.substring(path.lastIndexOf("\\\/")+1);
var filename=document.getElementById(''fname''+num);
if(fname.indexOf("\/")>-1)
{
filename.value = ""; alert("The ''/'' character is not allowed in the filename! Please specify another file name.");
}
else
filename.value = fname;
}

Any idea?



除了ie之外没有srcElement。更改代码,或为其他浏览器定义srcElement:

[PHP]


Event.prototype .__ defineGetter __(" srcElement",function (){b / b $ b $ var node = this.target;

while(node.nodeType!= 1){node = node.parentNode;}

返回节点;

}); [/ PHP]

there is no srcElement outside of ie. change the code, or define srcElement for other browsers:

[PHP]

Event.prototype.__defineGetter__("srcElement", function () {
var node = this.target;
while (node.nodeType != 1) {node = node.parentNode;}
return node;
});[/PHP]


这篇关于Mozilla上的Javascript?在IE上工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆