【发布时间】:2014-09-18 02:08:26
【问题描述】:
我在单独的 .js 文件中有一个名为 MyFunc() 的 jquery 函数。我想在按钮单击事件后面的 c# 代码中调用此函数。 (即如果数据添加成功,请致电 MyFunc() )。
原来这个函数是这样的
$(".next").click(function () {
点击asp:按钮时直接调用的地方。
<asp:button id="btnNext" runat="server" CssClass="next action-button" Text="Next" OnClientClick="return false"/>
所以我把函数改成
function MyFunc(){}
和按钮
<asp:Button ID="btnNext" runat="server" Text="Next" CssClass="action-button" OnClick="btnNext_Click1"/>
在按钮点击事件后面的代码中
Page.ClientScript.RegisterClientScriptInclude(GetType(), "MyScript", "Easying.js");
Page.ClientScript.RegisterClientScriptInclude(GetType(), "MyScript", "Reg.js");
Page.ClientScript.RegisterStartupScript(GetType(), "MyScript", "MyFunc()", true);
它没有给我任何错误。但它不起作用。 下面是函数。
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$(".next").click(function() {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({ opacity: 0 }, {
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50) + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ 'transform': 'scale(' + scale + ')' });
next_fs.css({ 'left': left, 'opacity': opacity });
},
duration: 800,
complete: function () {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
另外,如您所见,MyFunc() 用于从一个字段集更改为另一个字段集。我的 aspx 页面有 3 个字段集。和一个进度条(1--2--3)。进度条应该从一个移动到另一个。并且字段集也改变了。目前的情况是我看到进度条从 1 直接移动到 3。并且字段集没有变化。 这是我为它获取代码的地方。正如我上面提到的,当我直接从 aspx 页面调用它时,它工作得很好。 http://codepen.io/atakan/pen/gqbIz
这里是 MyFunc() !!
function MyFunc() {
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
if (animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({ opacity: 0 }, {
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50) + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ 'transform': 'scale(' + scale + ')' });
next_fs.css({ 'left': left, 'opacity': opacity });
},
duration: 800,
complete: function () {
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});};
【问题讨论】:
-
介意发布您的 MyFunc() 定义吗?
-
$(".next").click(function() 这是我改成 MyFunc() 的函数。它贴在上面!!
-
你有没有类
next的元素?你在新的button上省略了next类 -
是的,我省略了下一个类,因为我更改了函数。从 $(".next").click(function() 到 function MyFunc() ,因为我希望在代码隐藏按钮单击事件中调用该函数。
-
如果你只把$(".next").click的函数定义放到MyFunc()中,那么声明发生了什么? var current_fs、next_fs、previous_fs; //fieldsets var left, opacity, scale; //我们将动画化的字段集属性 var animating; //标志以防止快速多击故障它应该抛出一个错误变量未定义?
标签: c# jquery asp.net code-behind buttonclick