javascript - Div dissapears after I add script
问题描述
I have been trying to create an auto refreshing clock on my page but after adding script to my file the div around the clock dissapears so it doesn't use the CSS I have added to the div. <div class="clock_item">
is the one that disapears.
If I close div.clock_item
before div.clocktwo
then it doesn't dissapear but I want div.clocktwo
to stay inside div.clock_item
.
Thanks for the help!
function loadlink() {
$('.clocktwo').load('<?php echo get_template_directory_uri(); ?>/melbourne.php', function() {
$(this).unwrap();
});
}
loadlink();
setInterval(function() {
loadlink()
}, 5000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="clock_item">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 310 155" style="enable-background:new 0 0 310 155;" xml:space="preserve">
<path d="M64.9,44v102.6H36.5V44h-36V19.4h100.5V44H64.9z"/>
<path d="M105.3,146.7V19.4h28.4v101.9h54.2v25.3H105.3z"/>
<path d="M281.3,19.4h28.4v127.2h-28.4L220.6,67v79.7h-28.4V19.4h26.6l62.4,81.9V19.4z"/>
<path d="M0,154.9v-9.1h309.7v9.1H0z"/>
</svg> <!--// MEL LETTERS -->
<h3>
MELBOURNE
</h3>
<div class="clocktwo">
</div>
</div>
解决方案
我认为这可以解决不要在 div 标签中编写脚本
<div class="clock_item">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 310 155" style="enable-background:new 0 0 310 155;" xml:space="preserve">
<path d="M64.9,44v102.6H36.5V44h-36V19.4h100.5V44H64.9z"/>
<path d="M105.3,146.7V19.4h28.4v101.9h54.2v25.3H105.3z"/>
<path d="M281.3,19.4h28.4v127.2h-28.4L220.6,67v79.7h-28.4V19.4h26.6l62.4,81.9V19.4z"/>
<path d="M0,154.9v-9.1h309.7v9.1H0z"/>
</svg> // MEL LETTERS
<h3>
MELBOURNE
</h3>
<div class="clocktwo">
</div>
</div>
<script>
function loadlink(){
$('.clocktwo').load('<?php echo get_template_directory_uri(); ?>/melbourne.php',function () {
$(this).unwrap();
});
}
loadlink();
setInterval(function(){
loadlink()
}, 5000);
</script>
推荐阅读
- ios - EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 向图像添加过滤器时
- wordpress - 我是 wordpress 钩子的初创公司和新手。如何自定义启用和禁用添加到购物车按钮
- javascript - 防止浏览器不记得密码
- python - BeautifulSoup 逐行输出提取的文本
- c - 参数太少错误,但传入足够多的参数?
- android - 进度对话框在给定延迟后没有解散任何解决方案?
- flutter - Flutter,如何在侧面添加标签按钮?
- django - 在 django ModelViewSet 中写一个更薄的视图
- java - 将父版本外部化到 POM 中的变量
- python - 如何仅在python中从一天中的特定时间选择数据?