2016-09-26 14 views
1

私はインターネットで研究しようとしたが、私は彼/彼女はswalの中にHTMLを作ることを見て、私はコードをコピーし、それをonclick機能の中に入れた。私がそれをクリックするたびに、swalはそこにありますが、入力フィールドはありません。問題は入力フィールドが表示されない原因は何ですか?onclick関数でswal(sweetAlert内)を使用して2つの入力フィールドを挿入するにはどうすればよいですか?

<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

私のスクリプト、私は解決方法を確認してください。

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 
     } 
    }); 
関連する問題