gpt4 book ai didi

javascript - 为什么单击编辑时不出现警告框?

转载 作者:行者123 更新时间:2023-11-30 20:29:21 27 4
gpt4 key购买 nike

在我的代码中有一个 div 标签,其类为 class = specific 并且在 div 中有两个标签 `,.在 span 中有一些文本, anchor 标记如下所示:-

<a class="editByAnchor" id="0" href="#" data-toggle="modal" data-target="#thirdModal">
<i class="fa fa-edit">
</i>
</a>

模态

 <div class="modal fade" id="thirdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" style="margin: -1px;">
<div class= "content"></div>
<div id="specific_dates"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Update</button>
</div>
</div>
</div>
</div>

当我单击该图标时,我在 jQuery 的帮助下出现了一个问候警告框。但它不起作用。

jQuery 代码:-

$('.editByAnchor').on('click', function() {
alert("hello");
});

为什么它不显示警告框。谢谢。

最佳答案

您必须在 $(document).ready(function(){

中添加您的代码

<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('.editByAnchor').on('click', function() {
alert("hello");
});
});
</script>
</head>
<body>

<a class="editByAnchor" id="0" href="#" data-toggle="modal" data-target="#thirdModal">
<i class="fa fa-edit">
</i>Button
</a>
<div class="modal fade" id="thirdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" style="margin: -1px;">
<div class= "content"></div>
<div id="specific_dates"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Update</button>
</div>
</div>
</div>
</div>
</body>
</html>

关于javascript - 为什么单击编辑时不出现警告框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50526872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com