目前我在使用 jquery 表单插件时遇到问题。部分原因是我需要更改表单提交时的哈希值。这是我所做的基本工作:
$(document).ready(function() {
$('#search').ajaxForm({
target: '#pageContent',
success: function() {
$('#pageContent'); //this is all i need to 'ajaxify' this form
var hash = 'query='+encodeURI(document.getElementById('query').value);
window.location.hash = hash;
}
});
});
现在发生的事情是我能够更改哈希值,但我的表单不再是“ajaxify”本身,而是我只是得到一个空白页面..
我做错了什么?
最佳答案
由于没有人有合适的答案,我设法破解了 jquery.history.js 的实现,以允许通过 ajax 进行搜索。以下是代码:
$(document).ready(function() {
// bind form using ajaxForm
$('#search1').ajaxForm({
// target identifies the element(s) to update with the server response
target: '#pageContent',
// success identifies the function to invoke when the server response
success: function() {
$('#pageContent');
var hash = '#search.php?term='+($('#query').val()+'&submit=Submit').replace(/ /g, '+');
update(window.location.hash = hash);
}
});
});
我还替换了搜索中的空格以包含 +
符号..也许这会对某人有所帮助。
关于forms - 具有哈希更改功能的 jquery 表单插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5760726/