【问题标题】:Not able to call JQuery Popup from code behind无法从后面的代码调用 JQuery Popup
【发布时间】:2014-08-30 17:41:39
【问题描述】:

我是 Jquery 的新手。我面临的问题是,我可以从后面的代码中调用 alertbox,但是当我用 Jquery 函数替换 alertbox 时,出现错误“Microsoft JScript 运行时错误:'loadPopupBox' 未定义”

同样的函数 loadPopupBox() 在“文档就绪”运行时工作得非常好

    <script type="text/javascript">

   function myFunction() {
        loadPopupBox();  //This doesn't work while calling from code behind
        //alert("Hi");   // This works fine with code behind
    }

    $(document).ready(function () {


        loadPopupBox();  //This works fine with document load

        function loadPopupBox() {    
            $('#popup_box').fadeIn("slow");
            $("#container").css({ 
                "opacity": "0.3"
            });
        }
    });
</script>

后面的代码如下

protected void Button1_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "myFunction();", true);
}

非常感谢任何帮助。

问候 尼库尼

【问题讨论】:

    标签: jquery asp.net popup code-behind


    【解决方案1】:

    停止在$(document).ready 中定义函数。 如果您想在页面加载时调用函数,请在 $(document).ready 之外定义它,然后在其中调用它。

    像这样修改你的代码,它会正常工作:

    function myFunction() {
        loadPopupBox();
    }
    
    $(document).ready(function () {
        loadPopupBox();
    });
    
    function loadPopupBox() {    
        $('#popup_box').fadeIn("slow");
        $("#container").css({ 
            "opacity": "0.3"
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      相关资源
      最近更新 更多