-2
A
回答
0
這裏是一個示例代碼,其中包含@rickdenhaan使用jquery提出的建議。
// On double click show the input box
$("#text1").dblclick(function() {
$("#text1").hide();
$("#text1_input").val($("#text1").html()); // Copies the text of the span to the input box.
$("#text1_input").show();
$("#text1_input").focus();
});
// What to do when user changes the text of the input
function textChanged(){
$("#text1_input").hide();
$("#text1").html($("#text1_input").val()); // Copies the text of the input box to the span.
$("#text1").show();
// Here update the database
}
// On blur and on enter pressed, call the textChanged function
$("#text1_input").blur(textChanged);
$("#text1_input").keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
textChanged();
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="text1">Double click me to change me</span>
<Input id="text1_input" style="display:none"/>
對於使用JavaScript更新數據庫看到像堆棧溢出this職位。
在上面的代碼中,有一個帶有純文本和輸入框的跨度,供用戶更改文本。
輸入框在開始時不可見(style="display:none"
)。當用戶雙擊量程($("#text1").dblclick(function() {...});
)時,量程消失($("#text1").hide();
),出現輸入框($("#text1_input").show();
),並將量程內容複製到輸入框中以供用戶更改。
當用戶按下輸入框($("#text1_input").keypress(function (e) {...});
)或在輸入框外部的某處($("#text1_input").blur(textChanged);
)單擊時,輸入框消失並且跨度重新出現,但現在具有輸入框的編輯文本。
我希望這是有幫助的。如果你想要更多或其他東西,請讓我知道。
相關問題
- 1. jqGrid單元格編輯 - 雙擊編輯?
- 2. 雙擊jQuery內聯編輯?
- 3. 獲取數據雙擊不可編輯的Kendo計劃程序
- 4. 無法在phpmyadmin中編輯表格行
- 5. QTreeView編輯UserRole而不是DisplayRole雙擊
- 6. PyQt treeview編輯文本雙擊
- 7. 不可編輯的UITextView需要雙擊
- 8. 雙擊處理事件後退出/禁用編輯模式
- 9. 編輯文字後點擊
- 10. 在phpMyAdmin中存儲數組(雙打)
- 11. 複製phpmyadmin內聯編輯
- 12. 編輯phpmyadmin的BLOB字段
- 13. 在Swift中添加一個雙擊手勢來編輯和endEditing
- 14. 在Angular UI中雙擊編輯標籤名稱
- 15. 在sharedpreferences中編輯數據
- 16. 在AngularJS中編輯數據
- 17. 用戶雙擊一個按鈕後在數據庫中雙插入
- 18. 數據網格與編輯選項錯誤點擊編輯時
- 19. phpMyAdmin - 輕鬆編輯PHP序列化數據的方法?
- 20. 通過phpMyAdmin導入和替換已編輯的數據庫
- 21. 如何在雙擊文本(香草javascript)後編輯一個li元素?
- 22. 在asp:datagrid編輯命令中單擊編輯後如何訪問控件
- 23. 如何在從數據庫中讀取數據後編輯數據?
- 24. 雙擊OpenFaces樹/數據表
- 25. 如何在雙擊時禁用單元格可編輯選項
- 26. 雙擊編輯流星應用程序中的元素
- 27. 雙擊AngularJS中的每個換行編輯表
- 28. 空格鍵刪除編輯文本中的雙擊字母
- 29. 數據庫在phpMyAdmin
- 30. 雙擊後拖放
你應該像php使用jQuery和內聯編輯,以及你曾嘗試過的。 –
使用javascript捕獲doubleclick事件並用輸入替換文本值,綁定該新輸入上的onblur事件處理程序,以在用戶單擊或輸入外部製表符時捕獲,並使用AJAX將新值發送到服務器以更新具有新值的數據庫。 – rickdenhaan