javascript - 使用按钮 OnClick 事件调用 Javascript 函数

标签 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;" 但它不起作用,我还尝试使用 onclicentclick class=".next1 action-button" ="return false;" 这是可行的,但由于其他一些问题我不想使用它。

最佳答案

更改按钮 ID 与点击事件 ID 名称 next1 的匹配,并从按钮中删除 OnClick="btnfirstnext_Click"

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

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

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

关于javascript - 使用按钮 OnClick 事件调用 Javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37088763/

相关文章:

c# - System.ExecutionEngineException 仅在调试时出现

javascript - JQuery remove() 不适用于两个单词的 id

Jquery UI 可拖动不滚动可排序容器

Javascript:在用户完成滚动后执行操作

javascript - 在 PHP 中编码 JSON 并使用 POST 提交

C#解释流字符串例子

javascript - Chrome 开发者工具中 JavaScript 的奇怪行为

c# - 空检查在哪里?

javascript - Javascript cookie 是否可以保存到所有应用程序/webviews/inappbrowsers,而不是设备?

javascript - 在 Bootstrap 中将元素内容显示为工具提示的标题