Stripe.js applies several classes to every Stripe Element's container based on the state of the Element:
StripeElement--complete
StripeElement--empty
StripeElement--focus
StripeElement--invalid
StripeElement--webkit-autofill
(Chrome and Safari only)
You can read more about these classes, including how to customize them, in Stripe's documentation.
It sounds like checking for the StripeElement--empty
class might suffice for your use case. You can do something like this:
const cardElementContainer = document.querySelector('#card-element');
let cardElementEmpty = cardElementContainer.classList.contains('StripeElement--empty');
// Do things based on cardElementEmpty being true or false
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…