如何查找哪个控件调用了javascript函数 [英] how to find which control has invocked the javascript function

查看:60
本文介绍了如何查找哪个控件调用了javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我有javascript函数

hello friends

I have javascript function

function fillVC(e)
{
    .....
} 



我在两个控制事件中称呼此功能



I call this function in two control events

1.  <asp:DropDownList ID="ddlGeo" runat="server" Width="100px" 
                     onChange="fillVC(this);">
                </asp:DropDownList>   (in .aspx file)

2.  <asp:Button runat="server" id="btnSearch" Text="Search" 
                        onclick="btnSearch_Click"/>

protected void btnSearch_Click(object sender, EventArgs e)
    {
        this.GVDatabind();
        ClientScript.RegisterStartupScript(typeof(Page), "Open", "fillVC(this);", true);
    }        (in code behind file) 



谁能告诉我如何确定在哪个控件中调用了javascript,因此我可以在同一函数中执行不同的操作

知道如何执行此操作吗?

在此先感谢



Can anyone tell me how I can determine which control has called the javascript, based on that I can take different action in same function

Any idea how to do this??

Thanks in advance

推荐答案

基于控件的ID,我们可以使用control.type来检查控件的类型.


Based on the ID of the control we could use the control.type to check the type of the control.


function fillVC(controlClientId)
        {

            
            var control = document.getElementById(controlClientId);

            alert(control.type);

            if (control != null && control.type == "submit") {
                //control is a button
                alert('button')

            }

            else if (control != null && control.type == "select-one") {

                //control is dropdownlist 
                alert('dropdown')

 	}




您需要像这样调用函数...




You need to call the function like this...

<asp:dropdownlist id="ddlGeo" runat="server" width="100px" onchange="fillVC(this.id);" xmlns:asp="#unknown">
</asp:dropdownlist>


这篇关于如何查找哪个控件调用了javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆