gpt4 book ai didi

jquery - Bootstrap 4 在按钮中加载微调器

转载 作者:行者123 更新时间:2023-12-03 21:45:24 25 4
gpt4 key购买 nike

我正在尝试在按钮中实现 bootstrap 4 加载微调器,如下所示 Bootstrap Spinners .

下面是我在代码中所做的事情

my.html

<form class="form-inline" id="topicForm" action="" method="POST">
<input type="text" id="inputTopic" name="topic" class="form-control mb-2 mr-sm-2" placeholder="Topic of interest" required autofocus/>
<button type="button" id="btnFetch" class="btn btn-primary mb-2">Submit</button>
</form>

my.js

$(document).ready(function() {
$("#btnFetch").click(function() {
// load data via AJAX
fetch_data($("#inputTopic").val());
// disable button
$(this).prop("disabled", true);
// add spinner to button
$(this).html(
`<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Loading...`
);
});
});

除了引导文档中所示的微调器未显示之外,此方法有效。按钮文本按预期更改为 Loading...。想知道我没有对按钮内的微调器执行什么操作。

<强> Code Pen here

最佳答案

当您使用 4.0 时,您必须为此代码添加 Bootstrap 4.2.1

$(document).ready(function() {
$("#btnFetch").click(function() {
// disable button
$(this).prop("disabled", true);
// add spinner to button
$(this).html(
`<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...`
);
});
});
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<div style="margin:3em;">
<form class="form-inline" id="topicForm" action="" method="POST">
<input type="text" id="inputTopic" name="topic" class="form-control mb-2 mr-sm-2" placeholder="Topic of interest" required autofocus/>
<button type="button" id="btnFetch" class="btn btn-primary mb-2">Submit</button>
</form>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

关于jquery - Bootstrap 4 在按钮中加载微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522830/

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