简体   繁体   English

更改输入字段内的标签文本

[英]Change label text inside an input field

I whant to change the payment label("UepaPay") to credit/debit card.The vendor donen't allow me to change the payment method name, so I thought maybe I could change it with JS but... The problem here is that I working on wordpress so i can't change much of the code that I got.我想将付款标签(“UepaPay”)更改为信用卡/借记卡。供应商不允许我更改付款方式名称,所以我想也许我可以用 JS 更改它但是...这里的问题是我在 wordpress 上工作,所以我不能改变我得到的大部分代码。 I could change the label if have an ID or class but this is not the case.如果有 ID 或类,我可以更改标签,但事实并非如此。 Look at the picture:看图:

Label problem标签问题

¿Is a way to change the label text without having an id? ¿是一种无需 ID 即可更改标签文本的方法吗?

You can use the 'querySelelector' method to search for attributes.您可以使用 'querySelector' 方法来搜索属性。

 document.getElementById('change').addEventListener('click', () => { document.querySelector(['[for=payment-pay]']).innerHTML = 'Credit/Debit Card' })
 <label for='payment-pay'>Payment Pay</label> <button id='change'>Change to Credit/Debit Card</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM