【发布时间】:2020-01-10 12:36:31
【问题描述】:
我的 HTML 代码中有 3 个组件。 2 个 DIV 标签和 1 个按钮。我希望在单击按钮时重新加载第一个 DIV 标记。我已经应用了 jQuery,但单击按钮时没有发生任何事情。 这是我嵌入了 JS 代码的 HTML 代码。
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!--Font Awesome Icons-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<title>DIV Load Testing</title>
</head>
<body>
<button id="reloader" type="button" class="btn btn-primary btn-sm">
<i class="fas fa-chevron-circle-left"></i> Reload
</button>
<!--DIV TAG TO BE RELOADED ON THE BUTTON CLICK-->
<div class="container" id="content">
<h1>Reloads</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<img src="colorizer-desktop.PNG">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<!---->
<div class="container">
<h1>Test</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<img src="image-desktop.PNG">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#reloader').click(function(){
// alert('ok');
$('#content').load(' #content');
});
});
//function myButton() {
// location.reload();
// }
</script>
</body>
</html>
我使用了 2 个场景:
- 借助 jQuery。
- 借助
location.reload();函数。
通过location.reload() 函数,整个页面正在重新加载,但我只希望在单击按钮时重新加载第一个 DIV 标记。
请在此功能方面提供帮助!
【问题讨论】:
-
div 重载是什么意思?
-
那么您希望
reload做什么? -
重新加载一个 div 元素是什么意思?
-
为什么要加载不同的 jQuery 版本.. Bootstrap 的 JavaScript 至少需要 jQuery v1.9.1..
-
DIV重载是指通过点击@MayankPatel按钮刷新DIV元素的内容
标签: javascript jquery html jquery-ui dom-events