开发者

appended text immediately dissappears

When I add text to a div in a chrome extension popup, the text appears for a fraction of a second and then immediately dissappears again.

This is a small example:

<html>
  <head>
    <script>
      function show() {
        var newName = document.showMe.textToShow.value;
        var txt = document.createTextNode(newName);
        document.getElementById("feedback").appendChild(txt);
      }
    </script>
  </head>
  <开发者_JAVA百科;body>
    <form name="showMe">
      Name: <input type="text" name="textToShow" /><br />
      <input type="submit" value="Show" OnClick="show()" />
    </form>
    <div id="feedback"></div>
  </body>
</html>

What am I doing wrong?

Thanks,

Miel.


It works, but then the form gets submitted. You have to suppress sending the form like this

<input type="submit" value="Show" OnClick="show(); return false" />

or use a button:

<button type="button" onclick="show()">Show</button>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜