gpt4 book ai didi

javascript - Bootstrap 工具提示无法使用 JS

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:00 26 4
gpt4 key购买 nike

我试图让 Bootstrap 工具提示在我的应用程序中工作,但似乎没有任何效果..这让我有点发疯......我可以看到工具提示,但它看起来不应该..动画不起作用样式不起作用..我不知道如何解决..

我正在基于 javascript 构建 1-100% 的比例尺.. 当用户将鼠标悬停在其中一个比例尺上时,它会显示百分比 - 查看照片 enter image description here

这是我的代码:HTML:

{% load bootstrap %}
{% load static %}
{% load i18n %}
{% load survey_extras %}

<table class="table">
<!--<thead>
<tr>
<th> Question </th>
<th> Answers </th>
</tr>
</thead> -->
<tbody>
{% for form in response_form %}
{% if form.field.widget.attrs.category == category.name or not form.field.widget.attrs.category %}
<tr class="{% if form.errors%} danger {% endif %}">
<td>
<div class="container-fluid">
<div class="question-title row">
<div class="col-5">
<img src="{% static 'images/RightSpeech.jpg' %}" class="img-fluid" alt="Responsive image">
</div>
<div class="col-7">
<h5>{{ form.label|safe }}</h5>
</div>
</div></div>

{% if form.field.required %}
<span class="glyphicon glyphicon-asterisk" style="color:red"> </span>
{% endif %}
<span class="help-inline" style="color:red">
<strong> {% for error in form.errors %}{{ error }}{% endfor %} </strong>
</span> <br>

<div class="answers">
{% for field in form %}
<ul>
{{ field }}
</ul>
{% endfor%}

<!--{% if "hidden" in form.field.widget.attrs %}-->
<p id="check" hidden>{{ type }}</p>
{% if "scale" == type %}<br>
{% for scale in scales %}
{{ scale|safe }}
<div id="rate" class="scale"></div>
<div class="scale-title">
<div class="container">
<div class="row">
<div class="col scaleleft">
0%
</div>
<div class="col scaleright">
100%
</div>
</div>
</div>
</div>
<br>
{% endfor %}
{% elif 'choice-scale' == type %}
<br>
{% for scale in scales %}
<div class="row questionbox">
<div class="col-1">
<input onclick="peace(this)" name="{{ forloop.counter0 }}" type="checkbox" style="margin-right: 5px" class="checkbox">
</div>
{{ scale|safe }}
</div>
<br>
<div id="rate" class="scale"></div>
<div class="scale-title">
<div class="container">
<div class="row">
<div class="col scaleleft">
0%
</div>
<div class="col scaleright">
100%
</div>
</div>
</div>
</div>
<br><br>
{% endfor %}
{% endif %}
<!-- {% endif %} -->
</div>

</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

<script>
// Initialize tooltip component
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
// Initialize popover component
$(function () {
$('[data-toggle="popover"]').popover()
})
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});

</script>

JavaScript:

function createScale(which){
var index = parseInt(which);
for(var i = 0; i <= 100; i++) {
var strg = '<div class="numbers ' + i + ' ' + index + '"' +
'onclick=\'select(this)\' data-toggle="tooltip" data-placement="top" title= "' + i + '%"></div>';
classScale[index].innerHTML += strg;
}
}

我的 base.html 中的 header :

<head>
<meta charset="utf-8">
<title>SoftScore - Team Recruitment Analytics</title>
<!-- CSS-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="{% static '/css/master.css' %}">
<link href="{% static 'css/widgets.min.css' %}" rel="stylesheet" type="text/css">
<link href="{% static 'css/index.css' %}" rel="stylesheet">

<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico'%}"/>
<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico'%}"/>

<!-- Fonts-->
<link href="https://fonts.googleapis.com/css?family=Satisfy" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Ubuntu:300|Ubuntu:300italic" rel="stylesheet">
<link href="{% static 'vendor/font-awesome/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>

<!-- Plugin CSS -->
<link href="{% static "vendor/magnific-popup/magnific-popup.css" %}" rel="stylesheet">

<!-- Java Script-->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper-utils.js" integrity="sha256-h4TIzOvCoquQKCItCFCPbGMXDe7dbjSQsgZkeS396kA=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>



</head>

它应该是这样的: enter image description here

已编辑 img:enter image description here

CSS:

.scale{
display: inline-flex;
border: black 1px solid;
width:71%;
margin:auto;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
.numbers{
width: 5px;
height: 40px;
background-color: #66bb9e;
margin-right: 2px;
}

.numbers:hover {
background-color: #fa7770;
}

.scale-title{
display: inline-flex;
width:71%;
margin:auto;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
}


.scaleleft{
font-size: 0.7rem;
text-align: left;
}

.scaleright{
font-size: 0.7rem;
text-align: right;
}

.answers p{
margin-bottom: 3rem;
}

.scale-title .container .row .col{
padding-right:0;
padding-left: 0;
}

.tooltip-inner {
background-color:#fa7770;
margin-bottom: 3px;
font-weight: 400;
font-family: Ubuntu;
}

最佳答案

您的 JavaScript 在 DOM 外部创建相关的工具提示组件,这意味着您现在的初始化($(function() { }$(document).ready())不会影响这些元素。

对于通过 AJAX 或以其他方式在 DOM 之外插入的任何内容来说,这是一个非常常见的问题,并且需要对选择器的初始化方式进行微小的改动。

关于 Bootstrap,工具提示组件的一个选项可能是:

$('body').tooltip({
selector: '[data-toggle="tooltip"]',
container: 'body'
});

在上面的代码中,您将组件初始化为一个存在的元素 ( <body> ) 并声明将实际触发工具提示出现的选择器。这将影响您的 <body> 中的任何 元素不管它是否是初始 HTML DOM 的一部分。

注意:在上面的示例中,我指定了 container您可能认为有必要,也可能没有必要。您可以在此处阅读有关该特定选项(和其他选项)的更多信息:

https://getbootstrap.com/docs/4.0/components/tooltips/#options

关于javascript - Bootstrap 工具提示无法使用 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47819486/

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