使用javascript更改include路径


Using javascript to change include path

我正在使用此代码通过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;
 }

但是如何使用子按钮呢?

要在按钮上显示页面URL名称:

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

或者,在那里显示其他文本:

<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>

或者最后,使用隐藏字段&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>
$('button').onclick(function() {
$(location).attr('href', 'www.example.com'); //redirect to www.example.com
});

只需在HTML中完成即可。

 <form method="GET" action="?page=whatever">
     <input type="submit" value="Click Me!" />
 </form>

你可以试试这个:

<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;
 }

我希望这能有所帮助。