我怎样才能得到类似的内容:将输入框与网址连接,完成?
如果存在输入和提交的内容,则网址会更改为 #search / wasd 现在,如果我要将网址更改为 #search / wasdwasd 并且输入框值从 wasd 更改为 wasdwasd
<form name="input" action="" method="get">
Search: <input type="text" name="search">
<input type="submit" value="Submit">
<div id="result"></div>
</form>
-
$('form').submit(function() {
var form_data = ($(this).serialize());
window.location.hash = form_data.replace('=','/');
location.href = this.href + $('.search').val();
return false;
});
(function() {
window.App = {
Models: {},
Collections: {},
Views: {},
Router: {}
};
App.Router = Backbone.Router.extend({
routes: {
'': 'index',
'search/:search': 'search',
'*other': 'default'
},
index: function() {
$(document.body).append("");
},
search: function(){
$.post("script.php", $("form").serialize(), function(search) {
$('#result').html(search);
});
}
});
new App.Router();
Backbone.history.start();
})();