开发者

Virtual keyboard using ASCII codes

开发者 https://www.devze.com 2023-04-13 07:03 出处:网络
I created a virtual keyboard with the following sample code. <script type=\"text/javascript\"&g开发者_如何学Got;

I created a virtual keyboard with the following sample code.

<script type="text/javascript"&g开发者_如何学Got;
function vkb(vap){
document.forms["virtual"]["text"].value += vap;
}
</script>
<form name="virtual">
<input type="text" name="text"/>
<input type="button" onclick="vkb('a')" value="a" style="border:none;"/>
</form>

This code is unable to accept a ', and \ symbols. Then I modified my code in below way

<script type="text/javascript">
    function vkb(vap){
    document.forms["virtual"]["text"].value += vap;
    }
    function vkb1(){
    document.forms["virtual"]["text"].value += "'";
    }
    </script>
    <form name="virtual">
    <input type="text" name="text"/>
    <input type="button" onclick="vkb('a')" value="a" style="border:none;"/>
    <input type="button" onclick="vkb1()" value="'" style="border:none;"/>
    </form>

Now finally I have issue with only \ I am unable to add this stroke using my Virtual Keyboard. Can anybody help me how to add \ to textbox? Else anybody please provide me with the syntax to add \ using asci values.


Too long, didn't read :-)

Try this:

<script type="text/javascript">
    function vkb(vap) 
    {
        document.forms["virtual"]["text"].value += vap.value;
    }
</script>
<form name="virtual">
    <input type="text" name="text"/>
    <input type="button" onclick="vkb(this)" value="a" style="border:none;"/>
    <input type="button" onclick="vkb(this)" value="\" style="border:none;"/>
    <input type="button" onclick="vkb(this)" value="'" style="border:none;"/>
    <input type="button" onclick="vkb(this)" value='"' style="border:none;"/>
</form>

The advantage is that you don't have to write twice the letter of the key :-)

Your problem is that some characters sometimes need escaping (like the \ in javascript for example, it's used to do things like \n that means new line, so to have a \ you need to escape it with a second backslash, like \\)

Try running it for example here http://jsfiddle.net/T9Ptd/1/ or http://jsbin.com/uhakaq/3/edit


I don't know that you have included enough detail to answer your question. Keep in mind, though, that the '\' character is used as an escape character in javascript. That means you sometimes need to double it up, and sometimes even more depending on how many levels of interpretation you are passing through:

Try '\\' to get a slash into the code, or '\\\\' to get two slashes, which would pass one slash another layer down.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号