Modify the default font color and input font color of input and select using js.

Source: Internet
Author: User

Modify the default font color and input font color of input and select using js.

The default word color of textarea and the color of the word after the focus is obtained. After the focus is obtained, the default color disappears.

<Textarea cols = "50" rows = "5" id = "textarea" onfocus = "if (value = 'get element focal point') {value =''; document. getElementById ('textarea '). style. color = '# 000'} "onblur =" if (value = '') {value = 'element focus disappears'; document. getElementById ('textarea '). style. color = '# 000000'} "> enter the content you want to enter </textarea>

By default, the selected items in the select statement are in gray color and then black (implemented in js)

<script>var unSelected = "#999";var selected = "#333";$(function () {$("select").css("color", unSelected);$("option").css("color", selected);$("select").change(function () {var selItem = $(this).val();if (selItem == $(this).find('option:first').val()) {$(this).css("color", unSelected);} else {$(this).css("color", selected);}});})</script>

The input value has a default value and is gray. when clicked, the default value disappears and the input value turns black.

<Script type = "text/javascript"> $ (function () {// input $ (". form input [text] "). each (function () {$ (this ). setDefauleValue () ;}); // a single call $ ("# key "). setDefauleValue () ;}) // sets the default value $. fn. setDefauleValue = function () {var defauleValue = $ (this ). val (); values (this).val(defaulevalue}.css ("color", "# eee"); return this. each (function () {$ (this ). focus (function () {if ($ (this ). val () = defauleValue) {$ (this ). val ("" ).css ("color", "#000"); // the color of the input value }}). blur (function () {if ($ (this ). val () = "") {watermark (this(.val(defaulevalue0000.css ("color", "#999"); // The default color }});});} </script> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.