douzhang8144
douzhang8144
2013-06-24 11:46
浏览 11
已采纳

使用javascript更改包含路径

I'm using this code to change the include path with javascript:

$('#actionLink').attr('href', $('#actionLink').attr('href')  + '?page=welcome');


 switch($_GET['page'])) {
     case 'welcome':
         include 'section/welcome.html';
         break;
     case 'nda':
         include 'section/nda.html';
         break;
 }

But how do this using a submitbutton?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • drn1008
    drn1008 2013-06-24 11:57
    已采纳

    To show the page URL names on the buttons:

    <form method="get" action="<this page's address>">
        <input type="submit" name="page" value="page1" />
        <input type="submit" name="page" value="page2" />
    </form>
    

    Or, to show other text there:

    <form method="get" action="<this page's address>">
        <input type="submit" name="page" value="Page 1 button text" onclick="this.value='page1'" />
        <input type="submit" name="page" value="Page 2 button text" onclick="this.value='page2'" />
    </form>
    

    Or lastly, with a hidden field & jQuery:

    <form method="get" action="<this page's address>">
        <input type="submit" value="Page 1 button text" onclick="$('#hidden').val('page1')" />
        <input type="submit" value="Page 2 button text" onclick="$('#hidden').val('page2')" />
        <input type="hidden" name="page" id="hidden" />
    </form>
    
    点赞 评论
  • dow57588
    dow57588 2013-06-24 11:48
    $('button').onclick(function() {
    $(location).attr('href', 'www.example.com'); //redirect to www.example.com
    });
    
    点赞 评论
  • douhua1760
    douhua1760 2013-06-24 11:48

    Simply do it in HTML.

     <form method="GET" action="?page=whatever">
         <input type="submit" value="Click Me!" />
     </form>
    
    点赞 评论
  • dongxu1668
    dongxu1668 2013-06-24 11:57

    You can try this:

    <form method="POST" action="yourpage.php">
         ....
         <input type="hidden" name="page" id="page" value="welcome">
         <input type="submit" value="submit" />
     </form>
    
    // $_REQUEST works for both $_GET and $_POST
    switch($_REQUEST['page'])) {
         case 'welcome':
             include 'section/welcome.html';
             break;
         case 'nda':
             include 'section/nda.html';
             break;
     }
    

    I hope this can be of some help.

    点赞 评论

相关推荐