2011-08-25 22 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); 
    },