[英]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.