例如,如果有:
<div>New York</div>
所以我想像這樣列印另一個div:
<div>Free Delivery</div>
我將如何使用 JS 來做到這一點?
uj5u.com熱心網友回復:
你可以用簡單的js條件來做到這一點:
向元素添加類/ID<div id="country">New York</div>
在你的腳本中:
window.onload = () => {
const country = document.querySelector('#country');
const printdiv = '<div>Free Delivery</div>';
if(country && country.textContent.trim() == 'New York'){
document.querySelector('#country').insertAdjacentHTML('afterend',printdiv)
}
}
uj5u.com熱心網友回復:
將 id 添加到元素:
<div id="country">New York</div>
接著
let country = $('#country')
setInterval(()=>{
if(country.text()=='New York'){
// Your code
// exemple
alert('Congratulations ! We Ship for Free for New York
Customers');
}
},3000)
我希望它有用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/493191.html
標籤:javascript html jQuery 打字稿 dom
