我想使用Enter键将此contenteditable div的值动态发布到数据库。
有人帮忙吗?
<form method="POST" id="form_<?php echo $s; ?>">
<div class="r">
<textarea id="\'r_<?php echo $s; ?>\'" style="display: none;"></textarea>
<div contenteditable="true" class="r_e" holder="Write comment here..." id="r_<?php echo $s; ?>" onkeypress="enterKey(\'<?php echo $s; ?>\',\'r_<?php echo $s; ?>\')"></div>
</div>
<button id="rBtn_<?php echo $s; ?>" onclick="rs(\'<?php echo $s; ?>\',\'<?php echo $f; ?>\',\'r_<?php echo $s; ?>\',this)" style="position: absolute; height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" tabindex="-1"></button>
<script type="text/javascript">
function enterKey(a, b) {
window.addEventListener("keypress", function (event) {
var content = document.getElementById("r_"+a).innerHTML;
$("textarea#r_"+a) = content;
var button = document.getElementById("rBtn_"+a);
if(event.keyCode == 13) {
event.preventDefault();
button.click();
}
});
}
</script>