我想要拿出一個簡單的jQuery輸入水印功能。基本上,如果輸入字段沒有值,則顯示它的標題。使用jQuery將輸入TITLE顯示爲VALUE(包括jsfiddle)
我想出了必要的jQuery來分配輸入的值作爲它的標題,但它不顯示在頁面上,就好像它是一個手動編碼到表單中的值。
我怎樣才能得到這個顯示的值,當頁面加載到輸入字段中供用戶查看?
這裏的小提琴:http://jsfiddle.net/mQ3sX/2/
$(document).ready(function() {
$(".wmk").each(function(){
var value = $(this).val();
var title = $(this).attr("title");
if (value == '') {
value = title;
}
$(".result").text(value);
// You can see I can get something else to display the value, but it does
// not display in the actual input field.
});
});
即使療法e是小提琴的鏈接,您應該將相關代碼粘貼到您的問題中。 – 2012-04-10 18:08:59