我有以下HTML代码来创建表单:
<form method="POST" action="/post.php" name="signup">
<table>
<tr>
<td>URL:</td>
<td><input type="text" name="url" size="90" value=""/></td>
</tr>
<tr>
<td>Title: </td>
<td><input type="text" name="title" size="90"/> </td>
</tr>
</table>
</form>
我想做的是,当用户在
url
输入中输入URL时,得到页面的标题,然后脚本将其输出到title
输入中。为了从URL获得标题,我有一个PHP脚本。 最佳答案
您可以使用AJAX:
$(function() {
$('input[name=url]').change(function() {
// when the value of the url textbox changes
// which happens when the textbox looses focus
// send an AJAX request to the server script
// to query the title of the remote url
$.get('/gettitle.php', { url: $(this).val() }, function(result) {
// when the AJAX request succeeds update the value
// of the title input
$('input[name=title]').val(result);
});
});
});
关于javascript - 使用AJAX和jQuery完成表单输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4634085/