popover

J'ai utilisé des popovers Bootstrap et dans celui-ci, j'aimerais ajouter un href = "somelink". Mais cela semble impossible à faire avec la situation actuelle du code:

 <a 
          tabindex="0" 
          class="btn btn-link" 
          role="button" 
          data-toggle="popover" 
          data-trigger="focus" 
          title="Reaction Time (s)" 
          data-content="Enter the time it takes for a driver to react.
          Reaction times vary with age, distractions, alcohol or drug usage etc.
          The unit is seconds.">
              <i class="far fa-question-circle fa-2x"></i>
            </a>

Que dois-je faire pour obtenir un href dans ce texte popover?

2
Paul Davis 26 août 2020 à 17:28

3 réponses

Meilleure réponse

Vous devez passer html:true lors de l'initialisation de votre popover.

Code de démonstration :

$(function () {
$("[data-toggle=popover]").popover({html:true})//add html as true to use html 
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<a tabindex="0" class="btn btn-link" role="button" data-toggle="popover" data-trigger="focus" title="Reaction Time (s)" data-content="Enter the time it takes for a driver to react.
          Reaction times vary with age, distractions, alcohol or drug usage etc.
          The unit is seconds <a href='yoururl'>something</a>.">
  <i class="far fa-question-circle fa-2x">Click</i>
</a>

Consultez également ceci pour plus d'informations.

1
Swati 26 août 2020 à 14:36

As tu besoin de ça?

$("#testpopover").popover({
 html: true,
 title:"React time(s)",
 content: "Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum."+
 "<a class='btn btn-default'>HTML in popover</a>"
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>



<div style="width:100%; height:500px; margin-top:15%">
<a type="button" class="btn btn-default" id="testpopover">popover</a>
</div>
0
Apple Yellow 26 août 2020 à 14:51

Essayez de définir les options html comme true et sanitize comme false

https://getbootstrap.com/docs/4.3/getting-started/javascript/#sanitizer

$('[data-toggle="popover"]').popover({
  sanitize: false
})
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<a tabindex="0" class="btn btn-link" role="button" data-toggle="popover" data-html="true" data-trigger="focus" title="Reaction Time (s)" data-content="Enter the time it takes for a driver to react.
          Reaction times vary with age, distractions, alcohol or drug usage etc.
          The unit is seconds. <a href='https://stackoverflow.com/'>Go</a>">
  <i class="far fa-question-circle fa-2x"></i>?
</a>
0
User863 26 août 2020 à 14:37