我有以下 SweetAlert 代码..
<script type="text/javascript" charset="utf-8">
$('.patient-details').click(function(e) {
e.preventDefault();
var name = $(this).attr('data-name');
var gender = $(this).attr('data-gender');
var age = $(this).attr('data-age');
var country = $(this).attr('data-country');
var state = $(this).attr('data-state');
var address = $(this).attr('data-address');
var report = $(this).attr('data-report');
swal({
title: name,
text: "Gender: " + gender +"\n" + "Age: " + age +"\n" + "Country: " + country +"\n" + "State: " + state +"\n" + "Address: " + address +"\n" + "Report: " + report,
confirmButtonColor: "#00B4B4",
imageUrl: "images/avatar/user.png",
});
});
</script>
var 报告是一个链接,我需要在模态中显示该链接。我尝试了 html: true 等。不再使用 html。而是使用内容对象。正如医生所说:
https://sweetalert.js.org/docs/#content
https://sweetalert.js.org/guides/
但我作为新手无法理解它。
请求有关如何在模式中显示链接以及要在新窗口中打开的链接的帮助。
更新: 由于提供的解决方案不起作用,我使用另一种使用 html 的方法来解决它。需要删除文本,否则文本将是默认的。代码笔链接: https://codepen.io/pamela123/pen/GOJZgo
最佳答案
找到这个答案 here , 所有功劳归功于 Tristan Edwards
const el = document.createElement('div')
el.innerHTML = "Here's a <a href='http://google.com'>link</a>"
swal({
title: "Hello!",
content: el,
})
关于Javascript Sweet Alert 和文本中的 html 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47030856/