簡體   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