当我明显在$(document).ready之前包含jQuery库时,我无法弄清为什么它仍不能识别jQuery语法。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1"><title>

</title></head>
    <body>

        <form name="form1" method="post" action="jQueryDialogTest.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZA==" />

</div>


<script src="content/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="content/js/popup.js" type="text/javascript"></script>
            <div id="testDialog" winWidth="400" winHeight="500" winResizable="true">
                Some test mark-up, should show inside the dialog
            </div>
            <div><input type="button" id="invokeDialog" value="Click Me!" /></div>
        </form>

        <script type="text/javascript">

            $(document).ready(function()
            {
                $("input.invokeDialog").click.showDialog("#testDialog");
            });

        </script>

    </body>
</html>


在popup.js中,例如:

function showDialog(divID)
{
    // Get reference to the div element
    var dialogDiv = $(divID);

    dialogDiv.dialog
    (
        {
            bgiframe: true,
            modal: true,
            autoOpen: false,
            show: 'blind'
        }
    )

    dialogDiv.dialog("open");
}

最佳答案

您确定它实际上正在加载javascript文件吗?诸如“ Fiddler”之类的工具可以帮助您确定这一点。

另外,您的代码未正确终止,这可能会导致奇怪的错误。尝试这个:

$(document).ready(function()
            {
                $("input.invokeDialog").click.showDialog("#testDialog");
            }
);

关于jquery - $未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2631291/

10-11 22:12
查看更多