简体   繁体   English

设置占位符文本jQuery

[英]Setting placeholder text jQuery

I have this working code which I'm using to set placeholder values for username and password fields: 我有以下工作代码,用于设置用户名和密码字段的占位符值:

<script>document.getElementById("user_login").setAttribute("placeholder","Please enter your Email Address");</script>

and

<script>document.getElementById("user_pass").setAttribute("placeholder","Please enter your Password");</script>


Now I'm trying to apply this to a 3rd box which has the input ID #memb_password_send-1-email-input but this isn't a straight up element, it's an input field and using this ID (as above) obviously doesn't work. 现在,我尝试将其应用于第三个具有输入ID #memb_password_send-1-email-input框,但这不是简单的元素,它是一个输入字段,并且使用此ID(如上)显然不起作用”工作。

Here is a picture of console: 这是控制台的图片:

IMG 01

What would be the correct way to target this field with placeholder text? 用占位符文本定位此字段的正确方法是什么?

Same method used to provide placeholder for username and password fields would work in this case as well as those are input fields as well. 在这种情况下,也可以使用为用户名和密码字段提供占位符的相同方法,这些方法也是输入字段。 Just make sure that when you are writing this code in in-line script, do this after that input box has rendered ie after it's markup so that element is available to get selected. 只需确保在用内联脚本编写此代码时,请在呈现输入框后(即在标记后)执行此操作,以便可以选择元素。

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

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