简体   繁体   中英

jQuery from submit refreshes page

I want to make simple HTML page, something like "calculator". I need that values in table will appear after button clicking it will insert data into table but it will reload page itself - this not what I need, I need to see that data.

Is possible to do it? thanks, here is my form:

here is link to jsFiddle: http://goo.gl/6cWY0r

You should not mix up your form-submit with the calculations you are trying to do. On submitting a form the data gets sent to a server and the page will reload. If you want to avoid that simply create a button which does not submit your form like I did here:
http://jsfiddle.net/tdo6q9km/2/
So all you really have to do is to add another button

<button id="calc"> Calculate </button>

outside of your form.

$('button').on('click', function(e){
     $("table").append("<th scope=\"row\">1</th><td>Mark</td><td>Otto</td><td>@mdo</td>");
     e.preventDefault();
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM