[英]How to Insert dot(.) again in textarea, if we have created a function to replace it?
I have created a function to replace dot(.) into purnviraam, it works fine.我创建了一个 function 来将 dot(.) 替换为 purnviraam,它工作正常。 but If we need to insert ". " again in textarea, I have created a button neart textarea with function.
但是如果我们需要在 textarea 中再次插入“.”,我用 function 创建了一个靠近 textarea 的按钮。 it inserts dot"."
它插入点“。” but pressing shift, it also converts in purnviraam.
但按 shift,它也会转换为 purnviraam。 Please guide me, I don't have much knowledge of js coding.
请指导我,我对js编码的了解不多。
$(function() { $('textarea').on("keyup", function(e) { var val = $(this).val(); var str = val.replace('.', String.fromCharCode(2404)); $(this).val(str); }); }); function myFunction1() { insertfullstop.data.value += '.'; document.getElementById("data").focus(); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <tr> <td colspan="1"> <form id="insertfullstop"> <textarea type='text' id="data" class="js-copytextarea" style="width: 100%; max-width: 400px; height: 200px; border-radius: 6px 6px 6px 6px;" name="data" autofocus="" placeholder="Start Type Here................"></textarea> </form> </td> </tr> <tr align="right"> <td style="padding-top: 5px; float='center' padding-left: 1px; " colspan="1"> <strong style="font-size: 16px;"></strong> <button id="fullstop" OnClick="myFunction1()" class="btn1" title="Full Stop" type="button">.</button> </td> </tr> </table>
The problem is that you replace.问题是你换了。 with |
与 | on EVERY keyup event, which means that;
在每个 keyup 事件上,这意味着; you can add the dot with your function correctly but when you type the textarea it is going to replace the previously added dot with |
您可以使用 function 正确添加点,但是当您键入 textarea 时,它将用 | 替换先前添加的点
To solve this: check if the typed character is a dot or not.要解决这个问题:检查键入的字符是否为点。 If it is a dot, only then, replace it with a |.
如果它是一个点,那么只有用 | 替换它。 This way, it will not replace the previously added dot.
这样,它就不会替换之前添加的点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.