只弹出一次,使用cookie记录。复制内容到剪切板,使用原生js。
const activityModal = $('#modal-1024-activity')
const couponSuccessModal = $('#modal-1024-result-success')
const couponFailModal = $('#modal-1024-result-fail')
const couponBtn = activityModal.find('.coupon-btn-click')
const copyBtn = couponSuccessModal.find('.copy')
const copyInput = couponSuccessModal.find('.code')
const token = '9sPRorq5'
if (getCookie('1024-activity') && activityModal.length) {
activityModal.modal('show')
document.cookie = '1024-activity=true'
}
couponBtn.on('click', () => {
$.ajax({
type: 'POST',
url: '/purchase/promotions/receive_coupon/',
data: {
token,
},
success: (res) => {
couponSuccessModal.modal('show')
copyInput.val(res.coupon_num)
},
error: (res) => {
couponFailModal.modal('show')
},
})
})
copyBtn.on('click', () => {
copyInput.select()
document.execCommand('Copy')
window.location.href = '/vip'
})
function getCookie(name) {
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`)
const arr = document.cookie.match(reg)
if (arr) {
return false
}
return true
}
网友评论