简体   繁体   English

如果我们创建了一个 function 来替换它,如何在 textarea 中再次插入点(。)?

[英]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.

相关问题 滚动到指定位置时,如果我们再次返回到该位置,将启动该功能,如何将其重置并重新启动? - When scroll to a specified place, starts the function, how to reset it and start again, if we go back again to this place? 我们有一个基本的登录功能可以登录,但是随后突然返回到登录屏幕 - We have a basic login function that logs in, but then it abruptly goes back to the login screen again 如何检查我们是否已经使用ObservableSlim在对象上创建了代理? - How to check if we have already created proxy on Object using ObservableSlim? 如何在不立即执行“onclick”function 的情况下在我的文本区域中有“必需”? - How to have 'required' in my textarea without executing the 'onclick' function immediately? 如何使用javascript将一个textarea的值插入另一个textarea - how to insert value of an textarea to another textarea with javascript 如何在Javascript中用点替换逗号 - How to replace comma with dot in Javascript 如何替换文本区域中的换行符 - How to replace the line break in a textarea RegEx使用JavaScript中的点和替换功能实现最大长度 - RegEx for maximum length with dot and replace function in JavaScript 如何在函数中添加点 - How to add a dot in a function jQuery函数替换textarea文本不起作用 - jquery function to replace textarea text not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM