直接在元素上执行函数,而不是 document.getElementbyId 的结果
Perform function directly on element instead of result of document.getElementbyId
我的HTML中有一个ID为BaseGridView
的元素。如果我直接在其上调用函数,则一切正常,但是如果我通过document.getElementById()
获取该元素,则我的函数调用将不起作用。
例如:
BaseGridView.DoSomething();
对我来说一切都很好。
但是如果我这样做:
var hd = document.getElementById("HiddenforMainViewID");
var z = document.getElementById(hd.value);
z.DoSomething();
没有任何效果,Firefox说"TypeError:z.DoSomething不是一个函数"。hd
的值是"BaseGridView"
,z是一个实际元素。
有人可以向我解释为什么这不起作用吗?
编辑:
由于存在混淆,因此:
BaseGridView.DoSomething();
甚至可以工作,我真的不知道。我正在使用DevExpress,不知何故它能够做这样的事情。我一直在参考这个例子。
"TypeError: z.DoSomething not a function"和"z is a actual element"(即 Element
类的实例)表示 Element
类中没有可用的DoSomething
方法。
相关文章:
- 正在寻找比$(document).ready慢的$(window).load的替代方案
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 如何用更合适的内容替换document.write
- document.styleSheets不返回任何内容
- jQuery document.ready not working
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- reactjs this.refs vs document.getElementById
- 如何通过adf中的document.getElementById获取inputText字段值
- window.opener.document在ie中不起作用
- contentWindow.document.body is null
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- document.getElementById(“st”).click();不起作用
- $(document).height和$(window).heaght都返回相同的值-使用的是正确的doctype
- jQuery document.ready停止代码
- document.getElementById并使用id名称
- 使用jQuery 1.8.1准备好多个$(document).是否有任何开销
- document.getElementById在js中不起作用
- document.getElementById.style.backgroundImage not working
- 停止对document.ready函数的重定向/刷新
- 是否可以 document.getElementsByTagName('head')[0] ever 返回 null