Javascript 表单操作url的更改取决于#标记
是否可以根据浏览器标记使用jQuery/js更改表单操作Url 选项卡工作正常,我只需要更改操作即可 这是我目前使用的js选项卡,我也在使用jQuery地址插件:Javascript 表单操作url的更改取决于#标记,javascript,jquery,Javascript,Jquery,是否可以根据浏览器标记使用jQuery/js更改表单操作Url 选项卡工作正常,我只需要更改操作即可 这是我目前使用的js选项卡,我也在使用jQuery地址插件: var QTABS = { init: function () { // attached onload and change event to address plugin $.address.init(function(event) { // first load, set panel
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();
因为我不知道表单在哪里,也不知道您想如何访问它。如果要更改操作url以执行此操作:
$("form").attr("action", "Put your new Url here");
更新:
$("#tag")..attr("action", "Put your new Url here");
如果要使用标准Javascript,可以进行如下更改:
document.forms[0].action = "Put your new Url here";
注意:您可以用表单的名称替换表单[0]
更新:
如果您有一个id为的表单,则其类似于上面的方法调用:
document.getElementById("tag").action = "Put your new Url here";
这就是我成功使用的
$("#myDelete").click(function(){
$('#myForm').attr("action", "accounttrandelete.php");
$("#myForm").submit();
return false;
});
$("#myEdit").click(function(){
$('#myForm').attr("action", "accounttranedit.php");
$("#myForm").submit();
return false;
});
$("#myRec").click(function(){
$('#myForm').attr("action", "accounttranrec.php");
$("#myForm").submit();
return false;
});
$("#myUnRec").click(function(){
$('#myForm').attr("action", "accounttranunrec.php");
$("#myForm").submit();
return false;
});
我看不出问题出在哪里-如果您的代码正常工作,您可以轻松地向
init
和change
函数添加另一个函数。在新函数中,使用包含hashtag的事件对象并根据需要设置表单操作,例如:$(“#form”).attr('action',hashtag_或_某物)代码>谢谢你的回复,我想用#tag@neoszion为了防止误解,您是说“#tag”表示您的表单具有id属性吗?