gpt4 book ai didi

javascript - 为什么 JS 函数在我从 JSFiddle 中取出时不起作用?

转载 作者:行者123 更新时间:2023-11-28 15:19:44 24 4
gpt4 key购买 nike

<分区>

之前已经问过类似的问题,但所有/大多数人都建议我使用这个:

$(document).ready(function() {
// put your Javascript here
});

即使使用它仍然不起作用:

代码是 JSFiddle:http://jsfiddle.net/Guruprasad_Rao/ooexfj26/

HTML:

<html>
<head>
</head>
<body>
<div class="row">
<div class="col-xs-12 col-md-12">
<table class="table table-condensed table-hover table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
<tr>
<td>Johnn</td>
<td>Doe</td>
</tr>
<tr>
<td>Sam</td>
<td>Smith</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">EDIT</h4>
</div>
<div class="modal-body">
<p><input type="text" class="input-sm" id="txtfname"/></p>
<p><input type="text" class="input-sm" id="txtlname"/></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script src="modal.js" type="text/javascript"></script>
</body>
</html>

jQuery:

$(document).ready(function () {
$('table tbody tr td').on('click', function () {
$("#myModal").modal("show");
$("#txtfname").val($(this).closest('tr').children()[0].textContent);
$("#txtlname").val($(this).closest('tr').children()[1].textContent);
});
});

我什至尝试在最后添加这些仍然没有区别:

  <script src= "http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

结果:显示 html 的所有组件并且似乎不存在 JS 功能

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