是否有可能通过jQuery/js根据浏览器#tag更改表单动作的URL?表单动作的URL变化取决于#tag
这些标签正常工作,我只需要改变的行动。
这里是标签JS我目前使用的,我也使用jQuery插件地址也:
var QTABS = {
init: function() {
// attached onload and change event to address plugin
$.address.init(function(event) {
// first load, set panel
QTABS.setPanel(event);
}).change(function(event) {
// if the url changes, set panel
QTABS.setPanel(event);
});
},
// the core function to display correct panel
setPanel: function (event) {
// grab the hash tag from address plugin event
var hashtag = event.pathNames[0];
// get the correct tab item, if no hashtag, get the first tab item
var tab = (hashtag) ? $('.tabs li a[href=#' + hashtag + ']') : $('.tabs li:first a');
// reset everything to default
$('.tabs li').removeClass('activeTab');
$('.tab_container .tab_content').hide();
// if hashtag is found
if (hashtag) {
// set current tab item active and display correct panel
tab.parent().addClass('activeTab');
$('.tab_container .tab_content:eq(' + (tab.parent().index()) + ')').show();
} else {
// set the first tab item and first panel
$('.tabs li:first').addClass('activeTab');
$('.tab_container .tab_content:first').show();
}
if ($('.tabs').length)
{
// change the page title to current selected tab
document.title = tab.attr('title');
}
}
}
// Execute this script!
QTABS.init();
我可以看不出问题在哪里 - 如果你的代码有效,你可以轻松地将另一个函数添加到'init'和'change'函数中。在你的新函数中,使用包含hashtag的事件对象并根据需要设置表单动作,例如:$(“#form”)。attr('action',hashtag_or_something);' – WTK 2012-08-06 08:24:46