繁体   English   中英

我想将占位符属性添加到此DIV中的输入中,但是它没有可用来定位的唯一属性

[英]I want to add the placeholder attribute to the input within this DIV but it does not have a unique property that I could locate it with

我无法直接编辑HTML,因为Squarespace不允许这样做,只能使用JS和Jquery。

$("#field city :input").attr('placeholder', 'City');

我尝试使用此功能,但不起作用

<div class="field city">
                <label class="caption"><input class="field-element field-control" name="" x-autocompletetype="" type="text" spellcheck="false" data title="">
                </label>
              </div>

提前致谢

您的选择器对于提供的html不正确。

这有效:

$(".field.city .field-element").attr('placeholder', 'City')

小提琴

检查这个js小提琴 ..

<div class="field city">
  <label class="caption"><input class="field-element field-control" name="" x-autocompletetype="" type="text" spellcheck="false" data title="">
  </label>
</div>
<script>
    document.getElementsByClassName('field-element')[0].placeholder='city'
</script>

暂无
暂无

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

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