在事件上调用多个 javascript 函数

发布于 2024-08-12 09:59:43 字数 1232 浏览 2 评论 0原文

我正在使用 ajaxcontroltoolkit 并尝试在选项卡更改事件上调用几个函数。

我想从 OnClientActiveTabChanged 函数调用多个 js 函数,但不断收到错误

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR      1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET     CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Tue, 24 Nov 2009 12:31:43 UTC


Message: Expected '}'
Line: 202
Char: 181
Code: 0
URI: http://localhost/.../.../....aspx?ID=1000&propertyFrameWidth=1234&propertyFrameHeight=603&userId=9&employeeId=526&CCId=2&DbConnTag=TSDBConnection

更新,我刚刚注意到即使对于基本警报语句也会发生这种情况。

OnClientActiveTabChanged="alert('testone');alert('testtwo');"

给出问题的行:

Sys.Application.add_init(
function() 
{
    $create(AjaxControlToolkit.TabContainer, 
            {
             "activeTabIndex":0, 
             "clientStateField":$get("ctrlJobPropertiesView_tbcTabContainer_ClientState")
            },
            {
             "activeTabChanged":alert('testone');alert('testtwo');
            },
            null, 
            $get("ctrlJobPropertiesView_tbcTabContainer")
        );
});

I'm using the ajaxcontroltoolkit and trying to call a couple of functions on a tab changed event.

I want to call more than one js function from my OnClientActiveTabChanged function but keep getting the error

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR      1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET     CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Tue, 24 Nov 2009 12:31:43 UTC


Message: Expected '}'
Line: 202
Char: 181
Code: 0
URI: http://localhost/.../.../....aspx?ID=1000&propertyFrameWidth=1234&propertyFrameHeight=603&userId=9&employeeId=526&CCId=2&DbConnTag=TSDBConnection

Update, I've just noticed this happens even for basic alert statements..

OnClientActiveTabChanged="alert('testone');alert('testtwo');"

Line giving the problem:

Sys.Application.add_init(
function() 
{
    $create(AjaxControlToolkit.TabContainer, 
            {
             "activeTabIndex":0, 
             "clientStateField":$get("ctrlJobPropertiesView_tbcTabContainer_ClientState")
            },
            {
             "activeTabChanged":alert('testone');alert('testtwo');
            },
            null, 
            $get("ctrlJobPropertiesView_tbcTabContainer")
        );
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

作业与我同在 2024-08-19 09:59:43

盲目射击:尝试将其包装在匿名函数中,例如:

"activeTabChanged":function() { alert('testone');alert('testtwo'); }

编辑:我的解决了问题,gs 是最完整的。

Blind shot: try to wrap it in an anonymous function, like:

"activeTabChanged":function() { alert('testone');alert('testtwo'); }

EDIT: mine solves the problem, gs's is the most complete.

一萌ing 2024-08-19 09:59:43

这是你的问题:

{"activeTabChanged":alert('testone');alert('testtwo');}

我猜你想要的是 activeTabChanged 是一个函数,但 alert("something") 不返回函数,但什么也不返回。

字典中的分号在语法上是错误的。您想要将函数分配给 activeTabChanged

"activeTabChanged":function() { alert("testone"); alert("testtwo"); }

您不需要使用匿名函数。您也可以使用常规的。

function on_activeTabChanged() {
     // do something
}

// much later in the code
$create(AjaxControlToolkit.TabContainer,
        {"activeTabChanged":on_activeTabChanged});

Here's your problem:

{"activeTabChanged":alert('testone');alert('testtwo');}

I guess what you want is that activeTabChanged is a function, but alert("something") doesn't return a function but nothing.

The semicolons is syntactically wrong in a dictionary. You want to assign a function to activeTabChanged:

"activeTabChanged":function() { alert("testone"); alert("testtwo"); }

You don't need to use anonymous functions. You can also use regular ones.

function on_activeTabChanged() {
     // do something
}

// much later in the code
$create(AjaxControlToolkit.TabContainer,
        {"activeTabChanged":on_activeTabChanged});
属性 2024-08-19 09:59:43

将它们放在引号中

"activeTabChanged":"alert('testone');alert('testtwo')";

Put them in quotes

"activeTabChanged":"alert('testone');alert('testtwo')";
眼眸里的那抹悲凉 2024-08-19 09:59:43

尝试使用这个:

function callMultiple() {
   func1();
   func2();
   func3();
}

OnClientActiveTabChanged="callMultiple"

Try using this:

function callMultiple() {
   func1();
   func2();
   func3();
}

OnClientActiveTabChanged="callMultiple"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文