2011-03-01 44 views
7

我想有如何通过ajax更新输入文本的值?

  • 一个文本输入框,我可以
  • 更新与AJAX调用值(“获取当前修订”),然后
  • 另一个按钮(“更新代码库”)以使另一个AJAX调用文本框中的值

我不知道如何将所有这些结合在一起。

<form action="upgage.php"> 
    revision <input type="text" name="revision" value="" /><br /> 
    <input type="submit" value="update code base" /> 
<input type="submit" value="get current revision" /> 

</form> 

我想在jQuery中只有JavaScript使用jQuery的不

回答

6
<script> 
    document.getElementById('getValueButton').onclick = function() { 
     document.getElementById('revisionTextField').value = getRevisionViaAjax(); 
    } 
</script> 
6
<form action="upgage.php"> 
    <input type="submit" id="revision"/> <input type="text" id="passedValue" value="" /><br /> 
    <input type="submit" value="update" /> 
</form> 

现在:

$("#revision").click(function(event) { 
    event.preventDefault(); 
    $.post("/my/url/", function(data) { 
     $("#passedValue").val(data); 
    }); 

}); 

希望我理解正确的话你:P

相关问题