jquery .get funciton with insert from input text line
So I have the following
<div id="myscore"><div>
<input type="text" name="score" id="sc开发者_JAVA技巧ore" />
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#click').click(function(){
$('#myscore').get('computescore.php', $('#score').val(); )});
});
<div id="click"> <a href="#">click</a> </div>
The code will not pick up the value of score. How do you get the value of an input field into the a jquery function?
It updates the myscore field with the computed score after the score has been entered and clicked.
assuming computescore.php
just returns a single value, change:
$('#myscore').get('computescore.php', $('#score').val(); )});
to
$('#myscore').get(
'computescore.php',
function(data){ $('#score').val(data); }
);
you have to use a callback-function. take a look at the documentation for more information.
$("#score").val() will get you the current value correctly. I'm assuming you want to do something liek this, i.e. set the value of the text to what computescore.php returns?
$(document).ready(function() {
$('#click').click(function(){
$('#myscore').get('computescore.php', function(data){
$('#score').val(data);
});
});
});
精彩评论