如何更改输入元素的占位符文本?
例如,我有 3 个文本类型的输入。
<input type="text" name="Email" placeholder="Some Text">
<input type="text" name="First Name" placeholder="Some Text">
<input type="text" name="Last Name"placeholder="Some Text">
如何使用 JavaScript 或 jQuery 更改 Some Text 文本?
最佳答案
如果您想使用 Javascript,则可以使用 getElementsByName()
方法来选择 input
字段并更改每个字段的 placeholder
...看下面的代码...
document.getElementsByName('Email')[0].placeholder='new text for email';
document.getElementsByName('First Name')[0].placeholder='new text for fname';
document.getElementsByName('Last Name')[0].placeholder='new text for lname';
否则使用 jQuery:
$('input:text').attr('placeholder','Some New Text');
关于javascript - 更改占位符文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13506481/