Js implementation press Ctrl+Enter to send the effect

  • 2020-03-30 03:57:36
  • OfStack

1. Listen for the onkeydown event of the textarea


<textarea tabindex="1" class="ie6ta" name="contenthf.contenthf" onkeydown="keySend(event);" title=" According to the ctrl+enter Sent directly "></textarea>

2. Send the form, and then reload the opener window (see 4,)


function sbFrm() {
var Contenthf=document.getElementById("Contenthf");
var txtAr = Contenthf.getElementsByTagName("textarea")[0];
if (txtAr.innerHTML == "") {
txtAr.focus();
return false;
}
Contenthf.submit();
window.opener.afterReload();
return false;
}

3, when the CTRL key is pressed and the keycode is 13 (enter), the function that sends the form is called.


function keySend(event) {
if (event.ctrlKey && event.keyCode == 13) {
sbFrm();
}
}

4. If the current page is opened in window.open() mode, add a reload function to the page of window.open


function afterReload() {
setTimeout(function () {
window.location.reload();
}, 1000);
}

Related articles: