1,首先規定一下placeholder的規則
(1)文本框無内容失去焦點時,顯示placeher的文字(一般是灰色字型);
(2)文本框聚焦時(還沒有輸入内容),placeher将消失,即文本框空白
(3)文本框輸入内容時,placeholder也消失;
(4)文本框失去焦點時若有内容,則不顯示placeholder
2,核心方法
/***
* convert decimal str into hex(must be two bit,eg:02,f5)<br>
* '153'-->99
* @param str
*/
to2hex = function to2hex(str) {
var hex = parseint(str).tostring(16);
if (hex.length === 1) {
hex = '0' + hex;
}
return hex;
};
csscolor2hex = function (csscolor) {
var stringobj = csscolor.replace(/rgb[\s]*\(([\w,\s]+)\)[\s]*/i, "$1");
//console.log(stringobj);
var arr = stringobj.split(',');
var r = com.whuang.hsj.trim(arr[0]);
var g = com.whuang.hsj.trim(arr[1]);
var b = com.whuang.hsj.trim(arr[2]);
var rhex = to2hex(r);
var ghex = to2hex(g);
var bhex = to2hex(b);
return (rhex + ghex + bhex);
*
* @param hexcolor : #ccc
* @param csscolor : [string]rgb(153, 153, 153)
* @returns {boolean}
comparecolor = function comparecolor(hexcolor/*#789*/, csscolor/*rgb(153, 153, 153)*/) {
if (typeof csscolor !== 'string') {
return false;
if (hexcolor === csscolor) {//ie8,jquery.css('color') will get '#ddd',but 'rgb(204, 204, 204)'
return true;
if (com.whuang.hsj.startswith(hexcolor, '#')) {
hexcolor = hexcolor.substr(1);//delete '#' in front
if (hexcolor.length == 3) {
hexcolor = hexcolor.substr(0, 1) + hexcolor.substr(0, 1)
+ hexcolor.substr(1, 1) + hexcolor.substr(1, 1) + hexcolor.substr(2, 1) + hexcolor.substr(2, 1);
var cssresult = csscolor2hex(csscolor);
return (cssresult === hexcolor);
};