小编Jai*_*res的帖子

检查控件类型

我能够在打印它显示的页面中获取页面的所有控件的ID以及它们的类型

myPhoneExtTxt Type:System.Web.UI.HtmlControls.HtmlInputText
Run Code Online (Sandbox Code Playgroud)

这是基于此代码生成的

    foreach (Control c in page)
    {
        if (c.ID != null)
        {
            controlList.Add(c.ID +" Type:"+ c.GetType());
        }
    }
Run Code Online (Sandbox Code Playgroud)

但现在我需要检查它的类型并访问其中的文本,如果它的类型为HtmlInput,我不太清楚如何做到这一点.

喜欢

if(c.GetType() == (some htmlInput))
{
   some htmlInput.Text = "This should be the new text";
}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做,我想你明白了吗?

c# asp.net casting interface

16
推荐指数
1
解决办法
5万
查看次数

单击jQuery元素生成

我使用jQuery生成按钮:

var button_a = $("<button />", {
                        text: 'A',
                        click: do_something,
                        class: "button a"
               });

var button_b = $("<button />", {
                        text: 'B',
                        click: do_something,
                        class: "button B"
               });

function do_something(){
    alert("Button Was pressed");
}
Run Code Online (Sandbox Code Playgroud)

我想这样做do_something而不是:

function do_something(name){
    alert("Button " + name + " was pressed");
}
Run Code Online (Sandbox Code Playgroud)

我应该如何改变jQuery的按钮创建,这样我可以在一传nameclick: do_something

是预先创建封闭的唯一解决方案吗?

javascript jquery closures click

0
推荐指数
1
解决办法
53
查看次数

标签 统计

asp.net ×1

c# ×1

casting ×1

click ×1

closures ×1

interface ×1

javascript ×1

jquery ×1