2010-11-17 66 views

回答

7

這是Tumblr頁面中有問題的代碼。

 <input type="text" class="text_field" style="padding:0px; border-width:0px; text-align:right; width:325px; background:transparent;" 
    id="tumblelog_name" name="tumblelog[name]" 
              onfocus="$('tumblelog_name_background').style.backgroundColor = '#f9f8e4'; $('tumblelog_name_background').style.color = ''" onblur="$('tumblelog_name_background').style.backgroundColor = ''; if($('tumblelog_name').value == '') 
{ $('tumblelog_name_background').style.color = '#c1cfdd' }"/>.tumblr.com 

正如你所看到的額外的.tumblr.com根本不是輸入文本框的一部分。這是一個div,它的樣式看起來像它旁邊的文本輸入框。因此給它一個不可寫入的輸入文本字段的錯覺。

+2

+1爲你的複製和粘貼技巧:) – alex 2010-11-17 01:17:52

+0

確實:) ..... – 2010-11-17 01:48:32

0

可以解決一切與CSS,是輸入到包含不會以相同外觀改變的部分的div側面。

HTML在你的榜樣:

<div style="position:absolute; right: 8px; top: 4px; white-space: nowrap;"> 
    <input type="text" 
      class="text_field" style="padding:0px; border-width:0px; text-align:right; width:325px; background:transparent;" 
      id="tumblelog_name" 
      name="tumblelog[name]"  
      onfocus="$('tumblelog_name_background').style.backgroundColor = '#f9f8e4'; $('tumblelog_name_background').style.color = ''" 
      onblur="$('tumblelog_name_background').style.backgroundColor = ''; if($('tumblelog_name').value == '') { $('tumblelog_name_background').style.color = '#c1cfdd' }">.tumblr.com 
</div> 
0

您可以通過檢查你的文本框的onkeyup的價值做到這一點。在您的事件處理程序中,您可以確保文本框在用戶點擊某個鍵後說出任何您想要的內容。如果他們刪除了你的文字,你就把它放回去了。你也想確保你的處理程序也被稱爲onblur。

0

有沒有辦法做到這一點。如果您查看tumblr.com的來源,您可以看到「.tumblr.com」位於輸入標記之外。它只是簡單的造型。輸入框右邊框=無。並添加兄弟節點以繼續樣式。

<input type="text" class="text_field" style="padding:0px; border-width:0px; text-align:right; width:325px; background:transparent;" 
         id="tumblelog_name" name="tumblelog[name]" 
                onfocus="$('tumblelog_name_background').style.backgroundColor = '#f9f8e4'; $('tumblelog_name_background').style.color = ''" onblur="$('tumblelog_name_background').style.backgroundColor = ''; if($('tumblelog_name').value == '') 
`enter code here`{ $('tumblelog_name_background').style.color = '#c1cfdd' }" 
/>.tumblr.com 
相關問題