更改占位符文本 [英] Change placeholder text
本文介绍了更改占位符文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改输入元素的占位符文本?
How can I change the placeholder text of an input element?
例如,我有3个类型为text的输入。
For example I have 3 inputs of type text.
<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更改部分文字 / strong>或 jQuery ?我真的需要弄清楚这个来解决我的问题。
How can I change the Some Text text using JavaScript or jQuery? I really need to to figure this out to solve my problem.
推荐答案
如果你想使用Javascript那么你可以使用 getElementsByName()
选择输入
字段并更改占位符的方法
对于每一个...请参阅以下代码...
If you wanna use Javascript then you can use getElementsByName()
method to select the input
fields and to change the placeholder
for each one... see the below code...
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:
Otherwise use jQuery:
$('input:text').attr('placeholder','Some New Text');
这篇关于更改占位符文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文