Browse Source

Merge pull request #617 from tony/jquery-example-iteration1

jQuery example: submit on enter, focus field on load, ajax to callback function, " to '.
pull/625/merge
Kenneth Reitz 12 years ago
parent
commit
17fc38c397
  1. 18
      examples/jqueryexample/templates/index.html

18
examples/jqueryexample/templates/index.html

@ -2,19 +2,31 @@
{% block body %} {% block body %}
<script type=text/javascript> <script type=text/javascript>
$(function() { $(function() {
$('a#calculate').bind('click', function() { var submit_form = function(e) {
$.getJSON($SCRIPT_ROOT + '/_add_numbers', { $.getJSON($SCRIPT_ROOT + '/_add_numbers', {
a: $('input[name="a"]').val(), a: $('input[name="a"]').val(),
b: $('input[name="b"]').val() b: $('input[name="b"]').val()
}, function(data) { }, function(data) {
$("#result").text(data.result); $('#result').text(data.result);
$('input[name=a]').focus().select();
}); });
return false; return false;
};
$('a#calculate').bind('click', submit_form);
$('input[type=text]').bind('keydown', function(e) {
if (e.keyCode == 13) {
submit_form(e);
}
}); });
$('input[name=a]').focus();
}); });
</script> </script>
<h1>jQuery Example</h1> <h1>jQuery Example</h1>
<p><input type=text size=5 name=a> + <p>
<input type=text size=5 name=a> +
<input type=text size=5 name=b> = <input type=text size=5 name=b> =
<span id=result>?</span> <span id=result>?</span>
<p><a href=# id=calculate>calculate server side</a> <p><a href=# id=calculate>calculate server side</a>

Loading…
Cancel
Save