问题描述
我有一个适用于资源管理器但不适用于netscape的功能。
问题是第5行的功能。
1 fSetSelectedDay(myElement){
2 / *
3 ...
4 * /
5 var elementText = eval(myElement.children [" ; calDateText"]。innerText);
6 / *
7 ...
8 * /
9}
10<! - ... - >
11< td id = calCell onclick =''fSetSelectedDay(this)''>
12< font id =''calDateText''onclick =''fSetSelectedDay(this)''>
13< script> myMonth [w] [d]< / script>
14< / font>
15< / td>
16< ; - - ... - >
我需要一些支持。
非常感谢你。
..innerText仅限IE,因此无法在NS中运行。使用
innerHTML。
eval不需要那里:
var elementText =
document.getElementById(myElement).children(''calDa teText'')。innerHTML;
[]也是IE-ism。
-
兰迪
机会有利于准备好的心灵
comp.lang.javascript常见问题 -
同意,但是......
var elementText =
document.getElementById(myElement).children(''calDa teText'')。innerHTML;
....有这一行有两个问题:
1)如果你看一下OP的HTML,你会发现myElement是一个
的引用元素,而不是id。
2)儿童财产是
a)一个集合,所以括号是正确的,
b)也是微软主义。
或许
var elementText = myElement.childNodes [''calDateText''] .innerHTML;
会更好(最好有功能检测)?
Mike
-
Michael Winter
盖子(将.invalid替换为.uk以回复)
I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
1 fSetSelectedDay(myElement){
2 /*
3 ...
4 */
5 var elementText = eval(myElement.children["calDateText"].innerText);
6 /*
7 ...
8 */
9 }
10 <!-- ... -->
11 <td id=calCell onclick=''fSetSelectedDay(this)''>
12 <font id=''calDateText'' onclick=''fSetSelectedDay(this)''>
13 <script> myMonth[w][d] </script>
14 </font>
15 </td>
16 <!-- ... -->
I need some support for this.
Thank you very much.
..innerText is IE only, and as such is not going to work in NS. use
innerHTML instead.
eval is not needed there:
var elementText =
document.getElementById(myElement).children(''calDa teText'').innerHTML;
the [ ] are also an IE-ism.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Agreed, however...
var elementText =
document.getElementById(myElement).children(''calDa teText'').innerHTML;
....there are two problems with this line:
1) If you look at the OP''s HTML, you''ll see that myElement is a
reference to the element, not an id.
2) The children property is
a) a collection, so the brackets were correct,
b) also a Microsoft-ism.
Perhaps
var elementText = myElement.childNodes[ ''calDateText'' ].innerHTML;
would be better (preferably with feature detection)?
Mike
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
这篇关于children [" id"]。innerText - 不适用于netscape但使用资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!