使用按钮OnClick事件

时间:2016-05-07 12:50:14

标签: javascript c# jquery asp.net

我有一个按钮,如

<asp:Button ID="btnfirstnext" TabIndex="1" runat="server" Text="Next" class="action-button" OnClick="btnfirstnext_Click" />

我有像

这样的javascript
<script>
    $(function () {

        //jQuery time
        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


        $(".next1").click(function () {
            if (animating) return true;
            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'
              // $('btnfirstnext').trigger('click');

            });
        });

我想在点击按钮时调用此javascript 请帮我 我尝试了OnClientClick="javascript: return .next1;",但它不起作用,我也尝试使用class=".next1 action-button" onclicentclick="return false;",这是有效的,但由于其他一些问题,我不想使用它。< / p>

2 个答案:

答案 0 :(得分:1)

使用点击事件ID名称next1更改您的按钮ID匹配,并从按钮

中删除OnClick="btnfirstnext_Click"
<asp:Button ID="next1" TabIndex="1" runat="server" Text="Next" class="action-button" />

并更改您的函数参数,如下所示,这将调用此函数

$("#next1").click(function () {

答案 1 :(得分:0)

您可以尝试以下解决方案之一:

1)带功能

<asp:Button TabIndex="1" runat="server" Text="Next" class="action-button" OnClick="javascript:doSomething()" />

<script type="text/javascript">
function doSomething() {
   //do something
}
</script>

2)带有类(按钮定义中的类名前没有点)

<asp:Button TabIndex="1" runat="server" Text="Next" class="action-button next" />

<script type="text/javascript">
$(".next").click(function() {
   //do something
});
</script>

3)id

<asp:Button ID="next" TabIndex="1" runat="server" Text="Next" class="action-button" />

<script type="text/javascript">
$("#next").click(function() {
   //do something
});
</script>