0

是否可以根据浏览器#tag 使用 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
        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();
4

2 回答 2

0

因为我不知道表单在哪里以及您希望如何访问它。如果您想更改操作 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";

注意:您可以用forms[0]您的表单名称替换。

更新:

如果你有一个带有 id 的表单,那么它类似于上面的方法调用:

document.getElementById("tag").action = "Put your new Url here";
于 2012-08-06T08:25:37.223 回答
0

这就是我已经成功使用的

  $("#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;
    });
于 2012-08-06T08:25:49.653 回答