【问题标题】:jQuery Document Ready Function not Working [closed]jQuery Document Ready 功能不起作用[关闭]
【发布时间】:2016-02-07 05:30:57
【问题描述】:

我一直在尝试让一个页面在使用 jQuery 的 document.ready 函数完成加载后打开一个 lightwindow,但我不知道为什么它不起作用...

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="expires" content="">
<meta http-equiv="ImageToolbar" content="No">


<link href="css/style.css" rel="stylesheet" type="text/css">


<!-- Jquery -->            
<script src="js/jquery.js"></script>



<!-- add lightwindow stuff -->
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightwindow.js"></script>
<link rel="stylesheet" href="css/lightwindow.css" type="text/css" media="screen" />
<!-- finish adding lightwindow stuff -->

<link rel="icon" href="images/favicon.ico" type="image/x-icon" />






<style type="text/css">
body,td,th {
	font-size: 16px;
}
</style>

<script type="text/javascript">
        $myLightWindow.activateWindow({
			href: 'http://website.com', 
			title: 'website',
		  });
$(document).ready(myLightWindow);

</script>

</head>

<body>

我在页面中有链接,并且已验证 lightwindow 可以与外部站点一起使用。 lightwindow 来自这里:http://www.p51labs.com/lightwindow/#configure

谢谢-

布兰登

【问题讨论】:

  • $myLightWindow 和 myLightWindow 是什么?如果在外部脚本中定义,则发布相关代码。无论如何,您必须提供有问题的相关代码,如果没有相关的外部脚本,您的代码 sn-p 将毫无用处
  • 您好 A. Wolff,抱歉这是我的第一个问题 :)。 $myLightWindow 是 lightwindow.js 脚本中可以调用的函数,而 .activatewindow 函数应该在 iframe 中加载引用的外部页面:)
  • 好的,我检查了 chrome 中的页面,它说 undefined () 不是函数,我应该将函数“$myLightWindow”设置为函数吗?

标签: jquery html document onload ready


【解决方案1】:

您不是在创建函数,而是在调用函数。使用带有回调的ready 函数并在其中执行窗口激活。

<script type="text/javascript">
$(document).ready(function() {
    $myLightWindow.activateWindow({
        href: 'http://website.com', 
        title: 'website',
    });
});
</script>

【讨论】:

  • 我刚试过这个,它仍然没有加载,我嵌入在页面中的 iframe 停止了 document.ready 函数是否有问题?我尝试过的另一种选择是 函数...
【解决方案2】:

好的,我想我发现一个函数与 jQuery document.ready 函数发生冲突。我用测试脚本调用了 jquery。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>






<script type="text/javascript">
    ( function($) {
     // rely on $ within safety of "bodyguard" function
        $(document).ready( function() { alert("jquery functioning");  } );
    } ) ( jQuery );

    
    </script>

并让它告诉我 jquery 正在运行......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    相关资源
    最近更新 更多