您可以这样做,您需要为项目添加 ID。您可能想要做的一件事是验证用户输入。
HTML
<form action='' name='myform' id="myform" method='POST'>
<input type='text' name='cars' id="cars">
<button action='submit'>Search Cars</button>
</form>
jQuery
$('#myform').submit(function(){
var car = $('#cars').val();
$(this).attr('action', "http://www.mysite.com/" + car + ".html");
});
编辑:最好是页面底部的javascript;
满的
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action='' name='myform' id="myform" method='POST'>
<input type='text' name='cars' id="cars">
<button action='submit'>Search Cars</button>
</form>
<script src="path-to-jquery"></script>
<script>
// Shorthand for $(document).ready();
$(function() {
$('#myform').submit(function(){
var car = $('#cars').val();
$(this).attr('action', "http://www.mysite.com/" + car + ".html");
});
});
</script>
</body>
</html>