如何成功地设置一个值在JS字段?试穿了.专注但没有运气

How to successfully set a value to a field in JS? tried on.focus but no luck

本文关键字:字段 运气 JS 专注 成功 何成功 设置 一个      更新时间:2023-09-26

嗨,我想让我的输入字段说'输入您的电子邮件地址',当你点击它,它会消失,让用户输入它。我试着在SO中使用on:focus和其他各种技巧,但我无法让它起作用。有人能给我指个方向吗?你可以在heyscout.com上看到我在说什么。

在我的脚本标签,我有:

<script type="text/javascript">
JotForm.init(function(){
   $('input_1').hint('Enter your e-mail address');
});
</script>

对于输入字段,我有

        <div id="cid_1" class="form-input">
          <input type="email" class="form-textbox validate[required, Email]" id="input_1" name="q1_stayIn1" size="30"  />
        </div> 
            <button class="signup_btn" type="submit" class="form-submit-button">
              Okay!
            </button>

它应该工作,但我不完全确定是什么问题。

谢谢你的帮助!

如果你还不知道,如果你不需要支持旧的浏览器,你可以用纯HTML来做到这一点。

<input type="email" placeholder="Enter your e-mail address" class="form-textbox validate[required, Email]" id="input_1" name="q1_stayIn1" size="30" />

你就快成功了:

$('#input_1').hint('Enter your e-mail address');
   ^--------------- YOU NEED THIS TO SELECT ID

选择器就像CSS一样使用,所以你需要像#input_1一样瞄准它,例如

$('#input_1').hint('Enter your e-mail address');