日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

html5控制符置于底层,HTML5占位符在焦点上消失

發布時間:2023/12/20 HTML 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5控制符置于底层,HTML5占位符在焦点上消失 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Stefano J. Attardi寫了一個不錯的jQuery插件,只是這樣。

它比羅伯特的更穩定,并且當場得到焦點時,還會變淡到更淺的灰色。

我修改他的插件讀取占位符屬性,而不是手動創建跨度。

This fiddle具有完整代碼:

HTML

JS

// Original code by Stefano J. Attardi,MIT license

(function($) {

function toggleLabel() {

var input = $(this);

if (!input.parent().hasClass('placeholder')) {

var label = $('').addClass('placeholder');

input.wrap(label);

var span = $('');

span.text(input.attr('placeholder'))

input.removeAttr('placeholder');

span.insertBefore(input);

}

setTimeout(function() {

var def = input.attr('title');

if (!input.val() || (input.val() == def)) {

input.prev('span').css('visibility','');

if (def) {

var dummy = $('').text(def).css('visibility','hidden').appendTo('body');

input.prev('span').css('margin-left',dummy.width() + 3 + 'px');

dummy.remove();

}

} else {

input.prev('span').css('visibility','hidden');

}

},0);

};

function resetField() {

var def = $(this).attr('title');

if (!$(this).val() || ($(this).val() == def)) {

$(this).val(def);

$(this).prev('span').css('visibility','');

}

};

var fields = $('input,textarea');

fields.live('mouseup',toggleLabel); // needed for IE reset icon [X]

fields.live('keydown',toggleLabel);

fields.live('paste',toggleLabel);

fields.live('focusin',function() {

$(this).prev('span').css('color','#ccc');

});

fields.live('focusout','#999');

});

$(function() {

$('input[placeholder],textarea[placeholder]').each(

function() { toggleLabel.call(this); }

);

});

})(jQuery);

CSS

.placeholder {

background: white;

float: left;

clear: both;

}

.placeholder span {

position: absolute;

padding: 5px;

margin-left: 3px;

color: #999;

}

.placeholder input,.placeholder textarea {

position: relative;

margin: 0;

border-width: 1px;

padding: 6px;

background: transparent;

font: inherit;

}

/* Hack to remove Safari's extra padding. Remove if you don't care about pixel-perfection. */

@media screen and (-webkit-min-device-pixel-ratio:0) {

.placeholder input,.placeholder textarea { padding: 4px; }

}

總結

以上是生活随笔為你收集整理的html5控制符置于底层,HTML5占位符在焦点上消失的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。