I have a textarea
, On every Enter key pressed in textarea
I want new line to be started with a bullet say (*). How to go about it ?
请不要使用 jQuery。
I can observe for the Enter key , after that !? Should I have to get the whole value of textarea
and append * to it and again fill the textarea
?
你可以这样做:
<body>
<textarea id="txtArea" onkeypress="onTestChange();"></textarea>
<script>
function onTestChange() {
var key = window.event.keyCode;
// If the user has pressed enter
if (key === 13) {
document.getElementById("txtArea").value = document.getElementById("txtArea").value + "\n*";
return false;
}
else {
return true;
}
}
</script>
</body>
虽然按 Enter 键后的新行字符提要仍然存在,但它是获得您想要的内容的开始。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)