我有一個函數,只要點擊/關注,就可以將文本輸入設置爲「」。它可以很好地工作,當我將默認值編碼到一個數組中時,但是我不想這樣做,而是得到一個默認值的集合,這樣我就可以在多個頁面上使用它,而無需添加值來手動將值添加到陣列。獲取輸入值的集合
我通過所有輸入的試圖循環,並創建一個數組,但我福利局技能阻止我這樣做,這裏是我到目前爲止有:
$(function() {
var defaultValues = $('input[type="text"]').each(function) {
$(this).val();
)}; // instead of simply ["default value 1", "default value 2"]
$('input[type="text"]').live("focus", function() {
$(this).css("color", "#000000");
if (jQuery.inArray($(this).val(), defaultValues)) {
$(this).val("");
}
});
});
Oooops,一個錯字。我只會編輯... noooooooooooo!現在我必須重新開始! – Quentin
@Quentin - Just got that :) – karim79