<input type="text" value="useraname" />
<input type="password" value="password" />
我正在使用jQuery使內聯標籤在點擊/焦點上消失。密碼像往常一樣顯示公牛,但我想知道它是否可能以某種方式在密碼字段內顯示「密碼」標籤作爲文本(而不是••••)?密碼字段標籤
編輯添加:我想用戶鍵入的密碼被隱藏的課程!
謝謝
<input type="text" value="useraname" />
<input type="password" value="password" />
我正在使用jQuery使內聯標籤在點擊/焦點上消失。密碼像往常一樣顯示公牛,但我想知道它是否可能以某種方式在密碼字段內顯示「密碼」標籤作爲文本(而不是••••)?密碼字段標籤
編輯添加:我想用戶鍵入的密碼被隱藏的課程!
謝謝
有插件。例如,請參見labelify
如果您使輸入類型=「文本框」,您將能夠看到密碼。
Ofcourse,但然後密碼也將可見。我只需要標籤是文本。 – 3zzy 2009-12-10 05:22:16
即時通訊不知道你是什麼意思。 – Galen 2009-12-10 05:29:56
只要箱子獲得焦點,請將其更改爲type =「密碼」。據推測,你已經有了代碼清除箱子聚焦時的值,所以只需將它添加到那裏。 雖然插件路線可能會更好。 – McPherrinM 2009-12-10 05:31:35
我認爲您需要在密碼字段頂部動態覆蓋< input type =「text」>才能執行此操作。
查看下面的代碼。只需將addPassClear("Password")
附加到您希望使用此功能的任何輸入元素即可。
$(function() {
$.fn.addPassClear =
function(text)
{
return $(this).each(
function()
{
$(this).focus(function(event){$(this).passFocusize(text); $(this).select(); });
$(this).blur(function(event){$(this).passBlurize(text); });
});
}
$.fn.passFocusize =
function(text)
{
return $(this).each(
function()
{
if ($(this).val()==text && $(this).attr("type")=="text")
{
$(this).val("");
this.type="password";
}
});
};
$.fn.passBlurize =
function(text)
{
return $(this).each(
function()
{
if ($(this).val()=="")
{
$(this).val(text);
this.type="text";
}
});
};
};
爲什麼所有這些長腳本的?這絕對一個簡單的任務,可以用代碼半行來完成:
<input type='text' onclick="this.type='password',value=''" class='watever' value='password'..etc
歡呼
喜歡這個,但我認爲'onfocus'比'onclick'更好,因爲當用戶進入該領域時它也會觸發...... – neokio 2011-11-22 09:25:45
入住場標籤jQuery插件 http://fuelyourcoding.com/scripts/infield/
我的解決辦法是緊挨什麼丹上面提供。這裏
<script language="javascript" type="text/javascript">
function SwapLabel(id, label, alttype) {
$(id).focus(function() {
if (this.value == label) {
this.value = "";
if (this.type == 'text' && label == 'Password') {
this.type = alttype;
}
}
});
$(id).blur(function() {
if (this.value == "") {
this.value = label;
if (this.type == alttype && label == 'Password') {
this.type = 'text';
}
}
});
}
$(document).ready(function() {
SwapLabel('#UserName', 'Username', '');
SwapLabel('#Password', 'Password', 'password');
});
</script>
另一種方法是省略了「標籤」參數,只需使用「標題」值,這是labelify.js做基本上是什麼。如果需要,可以在labelify的部分中添加僅將這些事件處理程序應用於文本類型的所有輸入。或labelify下載並添加下面的代碼在需要的地方:
if (this.type == 'text' && label == 'Password') {
this.type = alttype;
}
if (this.type == 'text' && label == 'Password') {
this.type = alttype;
}
唯一的好處我片斷擁有labelify是它包括回答你原來的問題:
我不知道它可能以某種方式在密碼字段中顯示「密碼」標籤爲文本(而不是••••)?
除非我誤認爲插件文檔沒有提到密碼。我只是迅速將其中一種字段類型更改爲「密碼」,所有字符都變成了圓點。這是否與OP請求的密碼字段一起工作? – megaSteve4 2012-03-13 22:41:05
同樣的故事在這裏。它僅適用於文本字段,不適用於密碼字段。 – 2012-03-21 19:47:26