[英]sweet alert input to js variable
我想要一個甜美的警報輸入,要求用戶輸入一個值。 然后,我想將該值另存為JS變量,以供以后使用。
let coinName = swal("Enter cryptocurrency name", {content: "input"})
console.log(coinName)
這是我的完整代碼:
function getPrices() {
let coinName = swal("Enter cryptocurrency name", {content: "input"})
console.log(coinName.value)
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://api.coinmarketcap.com/v1/ticker/')+ coinName.valueOf + '/' + '&callback=?', function (data) {
console.log(data.contents);
})
var coinPrice = data.contents[0].price_usd
swal('Currently, in USD, 1 ' + coinName + ' is equal to $' + coinPrice)
}
這是我想做的:
我不確定我是否正確解釋了這一點,但是任何想法或建議都將不勝感激。
根據文檔https://sweetalert.js.org/guides/#using-dom-nodes-as-content,您可以使用
swal("Write something here:", {
content: "input",
})
.then((value) => {
// do something with value variable
});
如果我們更新您的代碼
function getPrices() {
swal("Enter cryptocurrency name", {content: "input"}).then(function(coinName) {
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://api.coinmarketcap.com/v1/ticker/')+ coinName + '/' + '&callback=?', function (data) {
console.log(data.contents);
var coinPrice = data.contents[0].price_usd
swal('Currently, in USD, 1 ' + coinName + ' is equal to $' + coinPrice)
})
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.