1
我發送了張貼請求,並用響應正文替換了當前html正文。 問題在於輸入文本在鼠標單擊時不能清除,並且沒有自動完成可用。當替換html正文時,輸入文本未被清除並且自動完成功能不起作用
我正在使用自動完成庫。
此代碼適用於響應來自服務器且未對主體進行任何修改的情況。
這是相關代碼:
$(document).ready(function() {
$('input, textarea').each(function() {
if ($(this).val() == '') {
$(this).val($(this).attr('Title'));
}
}).focus(function() {
$(this).removeClass('inputerror');
if ($(this).val() == $(this).attr('Title')) {
$(this).val('');
}
}).blur(function() {
if ($(this).val() == '') {
$(this).val($(this).attr('Title'));
}
});
};
window.onload = function()
{
$("#search_type").autocomplete("/company/autocomplete/",{
minChars: 2
});
};
這似乎是工作,但點擊後的值總是執行模糊功能不明確:
$('input, textarea').live('click',function() {
// CLEAR INPUT VALUE ---------------------------------------------------------------------------------------------------
$('input, textarea').each(function() {
if ($(this).val() == '') {
$(this).val($(this).attr('Title'));
}
}).focus(function() {
$(this).removeClass('inputerror');
if ($(this).val() == $(this).attr('Title')) {
$(this).val('');
}
}).blur(function() {
if ($(this).val() == '') {
$(this).val($(this).attr('Title'));
}
});
});
這就是我所做的,它的工作。 我需要做它顯示整個JS功能? – user1973995
作爲一個新用戶,我無法回答自己的問題。 解決方案很簡單,我只是使用live來綁定模糊和焦點事件。 – user1973995
'live()'已棄用,您應該找到不同的解決方案。 – Barmar