javascript - 具有输入类型范围问题的 Sweet alert 2 模态

标签 javascript jquery sweetalert2

有没有办法自定义显示输入值的输入(类型范围)旁边的输出? 我希望它显示值 + %。

到目前为止我尝试的是给输入一个自定义类,然后得到它的 <output>标记并尝试像这样操纵其内部文本:

$(document).on('input', 'input', function () {
$(".customSwal output").text( $(".customSwal").val() + " %" ) 
});

没有特别成功

$(document).ready(function(){

Swal.fire({
    
  icon: 'question',
  showCancelButton:'true',
  cancelButtonColor: '#d33',
  title: 'Test',
  text: 'Test',
  input: 'range',
  width: '25rem',
  inputAttributes: {
    min: 0,
    max: 100,
    step: 1,
   
    
  },
inputValue: 0,
  customClass: {
  input: 'customSwal',

}


})



});

//$(document).on('input', 'input', function () {
//$(".customSwal output").text( $(".customSwal").val() +  " %" ) 
//});
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>
</head>
<body>
</body>
</html>

最佳答案

您只需添加以下 CSS,即可将 % 字符添加到范围的输出中:

Swal.fire({
  input: 'range',
  inputAttributes: {
    min: 0,
    max: 100,
  },
  inputValue: 25
})
.swal2-range output::after {
  content: '%';
}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> 

关于javascript - 具有输入类型范围问题的 Sweet alert 2 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67222192/

相关文章:

javascript - 限制 Mustache.js 标签呈现的字符数

javascript - 通过javascript设置CSS li计数器值

javascript - 未捕获的类型错误 : Cannot read property 'then' of undefined SweetAlert & jquery

reactjs - SweetAlert 2 掩码输入

javascript - 检测 jQuery-ui droppable 中 Not Acceptable 拖放

javascript - Aurelia - 在下拉列表中设置默认值

javascript - Jquery、ajax : Clicking on a button and getting the value of the cell next to it on the same row

html - 如何使用内容元素将自定义 html 标签添加到 swal

javascript - 在 django 模板中嵌入 javascript 代码

jquery - 如何克隆表格标题行中除最后一列之外的每一列