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 に答える