简体   繁体   English

使用Jquery将Java语言加载到Div中

[英]Loading Javascript into Div with Jquery

I am trying to place a constantly updating Donation Ticker on my website that is currently located at http://www.ronpaul2012.com in the . 我正在尝试在我的网站(当前位于http://www.ronpaul2012.com)上放置一个不断更新的捐赠代码。 I have tried several solutions around stackoverflow including iframes, but my search abilities are either lacking or there is some java their site is running that I don't know how to work with (or I don't know a thing about javascript, but thats neither here nor there). 我已经尝试过一些围绕stackoverflow的解决方案,包括iframe,但是我的搜索能力不足或者它们的站点正在运行某些Java,但我不知道如何使用(或者我对javascript一无所知,但是既非这里也非那里)。 I played around with several variations and tried some document.ready calls, but I am not sure why nothing comes up. 我尝试了几种变体,并尝试了一些document.ready调用,但是我不确定为什么什么都没发生。

<head>
<meta charset="utf-8" />
<title>Ron Paul Donation Ticker</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>  
<script>
$('#ticker').load('https://secure.ronpaul2012.com/ #tickerContainer');
</script>

<body>

<div id="ticker"></div>

</body>

Thanks in advance! 提前致谢!

Your problem is that the javascript is executing before the div is present. 您的问题是div存在之前,javascript正在执行。 Use this to make the code wait to execute until the document is ready: 使用它使代码等待执行,直到文档准备就绪:

$(document).ready( function(){
   $('#ticker').load('https://secure.ronpaul2012.com/#tickerContainer');
 });

Also, I removed the space from your URL, which may have been an issue with loading at the right spot. 另外,我从您的网址中删除了空格,这可能是在正确位置加载的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM