スウィートアラートボックス1つのボタンが4つのボタンを追加します。同じボックスと同じdivを指している4つのボタンは、クリックすると最初のボタンです。この問題を解決する方法がないので、ポップアップに2番目のボタンポップアップが表示されます。スウィートアラートボックス私は4つのボタンをワンクリックで追加できます。
JS:
document.querySelector('ul.examples li.input button').onclick = function(){
swal({
title: "An input!",
text: 'Write something interesting:',
type: 'input',
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Write something",
},
function(inputValue){
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false;
}
swal("Nice!", 'You wrote: ' + inputValue, "success");
});
};
HTML:
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
</head>
<body>
<ul class="examples">
<li class="input"> <div class="ui"> <button> 1 </button> </div> </li> <br>
<li class="input"> <div class="ui"> <button> 2 </button> </div> </li> <br>
<li class="input"> <div class="ui"> <button> 3 </button> </div> </li> <br>
<li class="input"> <div class="ui"> <button> 4 </button> </div> </li> <br>
</ul>
</body>
</html>
<!-- end snippet -->
に従わなければならないので は '最初の要素に一致するセレクタをセレクタquerySelector'。すべての '.ui'要素に' click'イベントをバインドするには、 '$( '。examples .ui')。click(function(e){...}); – Tushar
あなたはコード –
を書き換えてください私は解答を理解していない私に言った –