-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. UITextView双击编辑
- 2. jqGrid单元格编辑 - 双击编辑?
- 3. 双击jQuery内联编辑?
- 4. 更改单击编辑双击网格
- 5. 在phpMyAdmin中编辑行不保存。 Magento不能设置数据
- 6. 获取数据双击不可编辑的Kendo计划程序
- 7. 无法在phpmyadmin中编辑表格行
- 8. PyQt treeview编辑文本双击
- 9. 编辑器窗体从按钮双击
- 10. 延迟双击编辑文本块WPF
- 11. QTreeView编辑UserRole而不是DisplayRole双击
- 12. Kendoui treeview节点双击事件编辑
- 13. 不可编辑的UITextView需要双击
- 14. 双击处理事件后退出/禁用编辑模式
- 15. 双击编辑Kendo Grid incell或内联编辑
- 16. 编辑文字后点击
- 17. 在phpMyAdmin中存储数组(双打)
- 18. 编辑后编辑QTableModel中的数据没有改变
- 19. Phpmyadmin编辑根权限| 127.0.0.1
- 20. 编辑phpmyadmin的BLOB字段
- 21. phpmyadmin bug:编辑插入
- 22. 编辑登录html phpmyadmin
- 23. 复制phpmyadmin内联编辑
- 24. 在tecplot中编辑数据
- 25. 在AngularJS中编辑数据
- 26. 在sharedpreferences中编辑数据
- 27. 在Swift中添加一个双击手势来编辑和endEditing
- 28. 在Angular UI中双击编辑标签名称
- 29. NSTableView可编辑标题并在表格中双击单元格
- 30. 按钮点击可编辑的数据
你应该像php使用jQuery和内联编辑,以及你曾尝试过的。 –
使用javascript捕获doubleclick事件并用输入替换文本值,绑定该新输入上的onblur事件处理程序,以在用户单击或输入外部制表符时捕获,并使用AJAX将新值发送到服务器以更新具有新值的数据库。 – rickdenhaan