我试图在互联网上进行研究,我看到他/她在swal中制作了一个html,然后我决定复制代码并将其放入onclick函数中。每当我点击它时,swal就在那里,但是没有输入字段。问题是输入字段没有出现的原因是什么?
<a id = "a" onclick = "divFunction()">Forgot Password</a>
我的剧本
<script type="text/javascript">
function divFunction(){
//Some code
swal({
title: 'Multiple inputs',
html: true,
text: '<h2>Login details for waybill generation</h2>'+
'<input id="swal-input1" class="swal2-input" autofocus placeholder="User ID">' +
'<input id="swal-input2" class="swal2-input" placeholder="Password">',
preConfirm: function() {
return new Promise(function(resolve) {
if (result) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
]);
}
});
}
}).then(function(result) {
swal(JSON.stringify(result));
})
}
</script>
答案 0 :(得分:0)
我有同样的问题,检查我是如何解决的:
var htmlContent = document.createElement("div");
htmlContent.innerHTML = "<input type=\"text\" id=\"field1\" class=\"someclass\" placeholder=\"sometext\" name=\"field1\" autocomplete=\"off\"> <input type=\"text\" id=\"field2\" class=\"someclass\" placeholder=\"sometext2\" name=\"field2\" autocomplete=\"off\">";
swal(msg, {
content: htmlContent,
buttons: ["No", "Yes"]
}).then((willDelete) =>{
if (willDelete) {
//actions if yes
}
});