按回车键提交包含可满足内容的div的附加表单



我想提交一个表单,其中包含一个可满足的div按下回车键。使用jquery .before()将表单添加到div中。

<form class="send" id="send_it<?php echo $seed['idd']; ?>" method="post" action="#">
    <div id="input_msg" contenteditable="true" 
          class="input<?php echo $seed['idd']; ?>" 
          style="width:210px; position:fixed; bottom:0;">
    </div>
    <input type="submit" value="send"  style="display:none;" />
</form>

这是你想要的:

$(document).keyup(function(e){
    if(e.keyCode== 13 || e.which== 13) { //if enter key is pressed
        var contentEditableValue=$('#input_msg').text(); //get the div value
        $('.send').append('<input type="hidden" value="'+contentEditableValue+'" id="valueToSend">'); //add a dummy input to the form to send the value
        $('.send').submit(); //submit the form
    }
});

最新更新