首页 > 解决方案 > set value of custom input before alert popup

问题描述

swal2({
  title: 'Messages',
  html: '<textarea id="text_messages" class="inpz textar" oninput="set_messages()" ></textarea>'
})

the problem is I need to set the value of textarea when it popup so when it shows it should already have the value I tried onfocus event for the textarea is working but need to focus to show the value, and I tried 'preConfirm'but I think its only trigger before html code load any idea of what I'm doing wrong

标签: javascriptsweetalertsweetalert2

解决方案


swal({
  html: '<textarea id="text_messages" class="swal2-textarea" rows="5"></textarea>',
  onOpen: function () {
    swal.getPopup().querySelector('#text_messages').value = 'custom value'
  }
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@7"></script> 


推荐阅读