文本框id没有为firefox定义错误,在IE中工作正常 [英] textbox id is not defined error for firefox, works fine in IE

查看:43
本文介绍了文本框id没有为firefox定义错误,在IE中工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发与购物车项目页面类似的东西。

是一个项目表。每个项目都有一个图像,一个qty

的文本框和一个添加按钮的图像。

单击添加图像时,它会将项目添加到购物车阵列中

如果商品已存在于购物车中,则将其汇总。

此代码在Internet Explorer和Firefox中完美运行,哎呀

我甚至测试过它在chrome中运行。

因此,当它只是

项目和javascript代码表时,所有浏览器的一切正常。但是这个代码被包含在另一个页面(带有菜单,页脚和标题的页面)中。它在firefox中错误输出

,并出现以下错误(在其他浏览器中正常工作):

txt9360303S未定义

[打破此错误] Cart [Item] = parseInt(Cart [Item] == undefine ...])+

parseInt(eval(textbox +''。value''));


('''''是因为调试器无法显示所有代码)

两个页面都在同一个目录中。


我正在想通过将它包含在另一个页面中,我有点搞砸了DOM。但我不知道如何。所以我想我想知道的是

有一个特定的firefox问题会导致这个问题。



下面是javascript函数我''使用和html作为

项之一。


< table>< tr>< td>< input type = text size = 2 value = 1 name =''txt9360303S''

id =''txt9360303S''>< / td>< td>< div id =''additem'' name =''additem''

onClick = AddItem(''936030 / 3S'')>< img src =''btnAdd1.jpg''border = 0>< / div> < /

td>< / tr>< / table>

Javascript函数:


var AddItem =功能(项目){


textbox =''txt''+ Item.replace(''/'','''')

购物车[ Item] = parseInt(Cart [Item] == undefined?0:Cart [Item])+

parseInt(eval(textbox +''。value''));

// DisplayItemQty(Item);

DisplayAllQty(购物车);

// ale rt(显示(购物车));


}

解决方案

Stever1975写道:
< blockquote class =post_quotes>
[...]它在firefox中错误输出

,出现以下错误(在其他浏览器中正常工作):

txt9360303S未定义

[打破此错误]购物车[Item] = parseInt(购物车[Item] == undefine ...])+

parseInt(eval(文本框) +''。value''));


('''''是因为调试器无法显示所有代码)

这两个页面都在同一个目录中。


我想通过将它包含在另一个页面中我有点搞乱

在DOM上。但我不知道如何。所以我想我想知道的是

有一个特定的firefox问题会导致这个问题。



极不可能。


[...]

下面是我正在使用的javascript函数和其中一个

项目的html。


< table>< tr>< td>< ;输入类型=文字大小= 2值= 1名=''txt9360303S''

id =''txt9360303S''>< / td>< td>< div id =' 'additem''name =''additem''

onClick = AddItem(''936030 / 3S'')>< img src =''btnAdd1.jpg''border = 0>< ; / div>< /

td>< / tr>< / table>


Javascript功能:

var AddItem = function(Item){


textbox =''txt''+ Item.replace(''/'','''') />
购物车[Item] = parseInt(Cart [Item] == undefined?0:Cart [Item])+

parseInt(eval(textbox +''。value'') );

// DisplayItemQty(Item);

DisplayAllQty(购物车);

//警示(显示(购物车) ));


}



您的标记无效且您的脚本代码非常糟糕。两者都很难清晰。一旦你修复了它,前者使用< http://validator.w3.org/>

而后者则应用< http://jibbering.com/faq/#evaland其他风格

指南,你可能会自己看清问题,所以不要再次问这个问题。


顺便提一下,FAQ 5.35应参考FAQ 5.34和5.10如何避免

eval()。

PointedEars

-

Prototype.js是由不懂javascript的人写的

谁不懂javascript。不知道javascript的人不是设计使用javascript的系统的最佳建议来源。

- Richard Cornford,cljs,< f8 ** *****************@news.demon.co.uk>


10月12日下午5:48, Thomas''PointedEars''Lahn< PointedE ... @ web.de>

写道:


Stever1975写道:


[...]在Firefox中错误输出

,出现以下错误(在其他浏览器中正常工作):

txt9360303S未定义

[打破此错误]购物车[Item] = parseInt(购物车[商品] ==取消定义...])+

parseInt(eval (textbox +''。value''));


('''''是因为调试器无法显示所有代码)

两个页面在同一目录中。


我正在想通过将它包含在另一个页面中我有点搞乱

在DOM上。但我不知道如何。所以我想我想知道的是

有一个特定的firefox问题会导致这个问题。



极不可能。


[...]

下面是我正在使用的javascript函数和

项之一的html。


< table>< tr>< td>< input type = text size = 2 value = 1 name =''txt9360303S' '

id =''txt9360303S''>< / td>< td>< div id =''additem''name =''additem''

onClick = AddItem(''936030 / 3S'')>< img src =''btnAdd1.jpg''border = 0>< / div>< /

td> < / TR>< /表>


Javascript函数:


var AddItem = function(Item ){


textbox =''txt''+ Item.replace(''/'','''')

Cart [Item] = parseInt(Cart [Item] == undefined?0:Cart [Item])+

parseInt(eval(textbox +''。value''));

// DisplayItemQty(Item);

DisplayAllQty(购物车);

// alert(显示(购物车));


}



您的标记无效且您的脚本代码非常糟糕。两者都很难清晰。一旦你修复了它,前者使用< http://validator.w3.org/>

而后者则应用< http://jibbering.com/faq/#evaland其他风格

指南,你可能会自己看清问题,所以不要再次问这个问题。


顺便提一下,FAQ 5.35应参考FAQ 5.34和5.10如何避免

eval()。


PointedEars

-

Prototype.js是由不懂javascript的人写的

谁不懂javascript。不知道javascript的人不是设计使用javascript的系统的最佳建议来源。

- Richard Cornford,cljs,< f806at


AIL

I''m working on something similiar to a shopping cart item page. There
is a table of items. Each item has an image, a textbox for the qty
and an image for the add button.
When the add image is clicked it adds the item to the cart array and
sums it if the item already exists in the cart.
This code works perfectly fine in Internet explorer and firefox, heck
I even tested it in chrome and it works.
So everything works fine in all browsers when it''s just the table of
items and the javascript code. But when this code is Included into
another page ( the page with menu, footer, and header). It errors out
in firefox with the following error (works fine in other browsers):
txt9360303S is not defined
[Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
parseInt(eval(textbox + ''.value''));

(the ''...'' is because the debugger could not display all the code)
Both pages are in the same directory.

I''m figuring that by including it in another page I''m some how messing
up the DOM. But I can''t figure how. So I guess what I''m wondering is
there a particular firefox gotcha that would cause this.


Below is the javascript function I''m using and the html for one of the
items.

<table><tr><td><input type=text size=2 value=1 name=''txt9360303S''
id=''txt9360303S''></td><td><div id=''additem'' name=''additem''
onClick=AddItem(''936030/3S'')><img src=''btnAdd1.jpg'' border=0></div></
td></tr></table>
The Javascript function:

var AddItem=function(Item){

textbox=''txt'' + Item.replace(''/'','''')
Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
parseInt(eval(textbox + ''.value''));
//DisplayItemQty(Item);
DisplayAllQty(Cart);
//alert(Display(Cart));

}

解决方案

Stever1975 wrote:

[...] It errors out
in firefox with the following error (works fine in other browsers):
txt9360303S is not defined
[Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
parseInt(eval(textbox + ''.value''));

(the ''...'' is because the debugger could not display all the code)
Both pages are in the same directory.

I''m figuring that by including it in another page I''m some how messing
up the DOM. But I can''t figure how. So I guess what I''m wondering is
there a particular firefox gotcha that would cause this.

Highly unlikely.

[...]
Below is the javascript function I''m using and the html for one of the
items.

<table><tr><td><input type=text size=2 value=1 name=''txt9360303S''
id=''txt9360303S''></td><td><div id=''additem'' name=''additem''
onClick=AddItem(''936030/3S'')><img src=''btnAdd1.jpg'' border=0></div></
td></tr></table>
The Javascript function:

var AddItem=function(Item){

textbox=''txt'' + Item.replace(''/'','''')
Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
parseInt(eval(textbox + ''.value''));
//DisplayItemQty(Item);
DisplayAllQty(Cart);
//alert(Display(Cart));

}

Your markup is not Valid and your script code is atrocious. Both are hardly
legible. Once you fixed that, the former using <http://validator.w3.org/>
and the latter by applying <http://jibbering.com/faq/#evaland other style
guides, you will probably see the problem clear enough by yourself so not to
ask this question again.

Incidentally, FAQ 5.35 should refer to FAQs 5.34 and 5.10 on how to avoid
eval().
PointedEars
--
Prototype.js was written by people who don''t know javascript for people
who don''t know javascript. People who don''t know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>


On Oct 12, 5:48 pm, Thomas ''PointedEars'' Lahn <PointedE...@web.de>
wrote:

Stever1975 wrote:

[...] It errors out
in firefox with the following error (works fine in other browsers):
txt9360303S is not defined
[Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
parseInt(eval(textbox + ''.value''));

(the ''...'' is because the debugger could not display all the code)
Both pages are in the same directory.

I''m figuring that by including it in another page I''m some how messing
up the DOM. But I can''t figure how. So I guess what I''m wondering is
there a particular firefox gotcha that would cause this.


Highly unlikely.

[...]
Below is the javascript function I''m using and the html for one of the
items.

<table><tr><td><input type=text size=2 value=1 name=''txt9360303S''
id=''txt9360303S''></td><td><div id=''additem'' name=''additem''
onClick=AddItem(''936030/3S'')><img src=''btnAdd1.jpg'' border=0></div></
td></tr></table>

The Javascript function:

var AddItem=function(Item){

textbox=''txt'' + Item.replace(''/'','''')
Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
parseInt(eval(textbox + ''.value''));
//DisplayItemQty(Item);
DisplayAllQty(Cart);
//alert(Display(Cart));

}


Your markup is not Valid and your script code is atrocious. Both are hardly
legible. Once you fixed that, the former using <http://validator.w3.org/>
and the latter by applying <http://jibbering.com/faq/#evaland other style
guides, you will probably see the problem clear enough by yourself so not to
ask this question again.

Incidentally, FAQ 5.35 should refer to FAQs 5.34 and 5.10 on how to avoid
eval().

PointedEars
--
Prototype.js was written by people who don''t know javascript for people
who don''t know javascript. People who don''t know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at


ail


这篇关于文本框id没有为firefox定义错误,在IE中工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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