开发者

javascript onclick working randomly

开发者 https://www.devze.com 2023-04-02 16:08 出处:网络
I am developing a virtual keyboard using PHP and JavaScript. Following is the simplest version. <html>

I am developing a virtual keyboard using PHP and JavaScript. Following is the simplest version.

  <html>
  <head>
  <link type="text/css" rel="stylesheet" href="styles.css"/>
  <script type="text/JavaScript" >
  function insert( s ) 
  {
        document.getElementById('comment').innerHTML+= s;
  }
  </script>
  </head>
  <body>

  <table>
        <tr>
              <td class="cell" ><p onclick="insert(this.innerHTML)" >a</p></td>
              <td class="cell"><p onclick="insert(this.innerHTML)">b</p></td>
        </tr>
        <tr>
              <td class="cell" ><p onclick="insert(this.innerHTML)">c</p></td>
              <td class="cell"><p onclick="insert(this.innerHTML)">d </开发者_C百科p></td>
        </tr>
  </table>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
        <textarea name="comment" id="comment"> </textarea>
        <input type='submit' value='Enter' name='beta' />
  </form>
  <?php
  if(isset($_POST['beta']))
  {
        echo $_POST['comment'] ;
  }
  ?>

  </body>
  </html>

It works fine untill I type in the <taxtarea> from the laptop, after which it does not take input from the virtual keyboard.


You should use the value attribute of the textarea. Not innerHTML :

document.getElementById('comment').value += s;

0

精彩评论

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