2011-08-25 36 views
2

Microsoft AJAX jscript $发现不能在隐藏/不可见元素上工作吗? 我似乎无法得到它的工作,但我不知道这是否是预期的行为。

+1

为什么不直接使用的document.getElementById(“富”),这将不可见元素的工作? – jfriend00

+0

我同意jfriend00;您可以使用$ get作为getElementById方法的快捷方式 – Romhein

+0

$ get,$ find,document.getElementById(“foo”)在DOM中查找所有元素,而不管应用了什么CSS(display:none; visibility:hidden .. 。等等)。 –

回答

4

如果你设置了一个控制falseVisible属性,那么$find不会找到任何东西,因为asp.net不会产生与Visible属性设置为false控件的HTML。但它应该工作,如果您使用CSS/JavaScript隐藏控制。

+0

+1刚刚疯了,直到我意识到这一点 –

0

你是积极的元素是在DOM(即:可见= True)?下面是一些reference info为预期的行为:

$find实际调用findComponent

Sys.Application = new Sys._Application(); 
window.$find = Sys.Application.findComponent; 

findComponent: function _Application$findComponent(id, parent) { 
     /// <summary locid="M:J#Sys.Application.findComponent">Finds top-level components that were added through addComponent if no parent is specified or children of the specified parent. If parent is a component</summary> 
     /// <param name="id" type="String">The id of the component to find.</param> 
     /// <param name="parent" optional="true" mayBeNull="true">The component or element that contains the component to find. If not specified or null, the search is made on Application.</param> 
     /// <returns type="Sys.Component" mayBeNull="true">The component, or null if it wasn't found.</returns> 
     //#if DEBUG 
     var e = Function._validateParams(arguments, [ 
      {name: "id", type: String}, 
      {name: "parent", mayBeNull: true, optional: true} 
     ]); 
     if (e) throw e; 
     //#endif 
     // Need to reference the application singleton directly beause the $find alias 
     // points to the instance function without context. The 'this' pointer won't work here. 
     return (parent ? 
      ((Sys.IContainer.isInstanceOfType(parent)) ? 
       parent.findComponent(id) : 
       parent[id] || null) : 
      Sys.Application._components[id] || null); 
    },