[精讚] [會員登入]
3084

[CSS] placeholder 屬性的CSS怎麼設定?

常會用到的placeholder可以在沒填值時有提示的文字,想要改變格式該怎麼做?

分享此文連結 //n.sfs.tw/14816

分享連結 [CSS] placeholder 屬性的CSS怎麼設定?@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2020-12-04 08:52:08 最後編修
2020-11-19 15:19:06 By 張○○
 

自動目錄

常會用到的placeholder可以在沒填值時有提示的文字,想要改變格式該怎麼做?

HTML

<label>姓名:
<input type="text" placeholder="王大明" />
</label>

結果

預設的樣式是淺灰色,想要修改他的樣式:

使用STYLE屬性

在標籤中的style屬性無法修改到placeholder的樣式。

 

使用CSS

/* input tag */
input::placeholder { color: yellow; }

/* textarea tag */
textarea::placeholder { color: green; }

/* all tag */
::placeholder { color: #a4dbb7; }

/* 指定CHROME, EDGE,  */
::-webkit-input-placeholder { color: grey; }

/* 指定firefoX */
::-moz-placeholder { color: yellow; }

placeholder 屬性是由 ::placeholder 選擇子(selector)來決定。

使用JQUERY/JAVASCRIPT

HTML

<input type="text" name="namae" id="namae" placeholder="王大明" />

JAVASCRIPT取值

var ph= document.getElementsByName('namae')[0].placeholder;

var ph2 = document.getElementById ("namae").placeholder;

JAVASCRIPT給值

document.getElementsByName('namae')[0].placeholder= "Some New Text";

document.getElementById ("namae").placeholder= "Some New Text";

JQUERY取值

var ph3= $('#namae').attr('placeholder');

var ph4= $('input[name ="namae"]').attr('placeholder');

JQUERY給值

$('input:text').attr('placeholder','Some New Text');

$('#namae').attr('placeholder','Some New Text');

參考資料

[1] https://www.w3schools.com/csSref/sel_placeholder.asp

[2] https://css-tricks.com/almanac/selectors/p/placeholder-shown/

[3] Change placeholder text https://stackoverflow.com/questions/13506481/change-placeholder-text/13506567

 

END

你可能感興趣的文章

textarea計算字數和行數 textarea可以大量的放入文字,但要如何計算字數和行數呢?

如何讓瀏覽器每次都重新載入css、js、圖檔 不管怎麼刷新網頁,他總是跑出來舊的內容,這對開發的人來說很困擾...

[CSS] 多個 class 的表示法和寫法 網頁設計中常會用到CSS,他的一般格式是這樣的:

[HTML5] script 的新增屬性 defer, async script 的新增屬性 defer, async

[CSS] placeholder 屬性的CSS怎麼設定? 常會用到的placeholder可以在沒填值時有提示的文字,想要改變格式該怎麼做?

CSS 垂直中文字 要把文字垂直顯示的處理中文字正轉或逆轉90度的css設定

隨機好文

沒有非誰做不可的事,也沒有不可被取代的人 沒有非誰做不可的事,也沒有不可被取代的人

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

APACHE的記錄檔格式 LogFormat 語法 在APACHE中有定義一些記錄的語法模版 在 /etc/httpd/conf/httpd.conf 中: LogForm

[NetBeans] 使用git複製別人的專案 NetBeans使用git複製別人的專案及版本控制

[MAC] 安裝APACHE+PHP OS Darwin OpenIDMac1deAir 15.6.0 Darwin Kernel Version 15.6.