Javascript Microsoft AJAX jscript$find对隐藏/不可见元素不起作用吗?

Javascript Microsoft AJAX jscript$find对隐藏/不可见元素不起作用吗?,javascript,asp.net,ajax,Javascript,Asp.net,Ajax,Microsoft AJAX jscript$find对隐藏/不可见元素不起作用吗? 我似乎无法让它工作,但我不知道这是否是预期的行为。如果将控件的Visible属性设置为false,则$find将找不到任何内容,因为asp.net不会为Visible属性设置为false的控件生成html。但是如果您使用css/javascript隐藏控件,它应该可以工作。您确定元素在DOM中(即:Visible=True)吗?以下是一些预期行为: $find实际调用findComponent: Sys.App

Microsoft AJAX jscript$find对隐藏/不可见元素不起作用吗?
我似乎无法让它工作,但我不知道这是否是预期的行为。

如果将控件的
Visible
属性设置为
false
,则
$find
将找不到任何内容,因为asp.net不会为
Visible
属性设置为
false
的控件生成html。但是如果您使用css/javascript隐藏控件,它应该可以工作。

您确定元素在DOM中(即:Visible=True)吗?以下是一些预期行为:

$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);
    },
Sys.Application=new Sys.\u Application();
窗口。$find=Sys.Application.findComponent;
findComponent:函数_应用程序$findComponent(id,父级){
///如果未指定父级或指定父级的子级,则查找通过addComponent添加的顶级组件。如果父级是组件
///要查找的组件的id。
///包含要查找的组件的组件或元素。如果未指定或为null,则对应用程序进行搜索。
///组件,如果找不到,则为null。
//#如果调试
var e=函数。\u验证图(参数[
{name:“id”,类型:String},
{name:“parent”,mayBeNull:true,可选:true}
]);
如果(e)抛出e;
//#恩迪夫
//需要直接引用应用程序单例,因为$find别名
//指向没有上下文的实例函数。“this”指针在此不起作用。
返回(父母?
((Sys.IContainer.isInstanceOfType(父级))?
父.findComponent(id):
父项[id]| | null):
系统应用程序_组件[id]| | null);
},

为什么不直接使用document.getElementById(“foo”)来处理不可见的元素呢?我同意jfriend00;您可以使用$get作为getElementById方法$get,$find,document.getElementById(“foo”)的快捷方式,在DOM中查找所有元素,而不管应用了什么CSS(显示:无;可见性:隐藏…等)。