0

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

但是如何使用提交按钮呢?

4

4 回答 4

1

要在按钮上显示页面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>
于 2013-06-24T11:57:10.897 回答
0

你可以试试这个:

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

我希望这能有所帮助。

于 2013-06-24T11:57:39.643 回答
0
$('button').onclick(function() {
$(location).attr('href', 'www.example.com'); //redirect to www.example.com
});
于 2013-06-24T11:48:14.843 回答
0

只需在 HTML 中完成。

 <form method="GET" action="?page=whatever">
     <input type="submit" value="Click Me!" />
 </form>
于 2013-06-24T11:48:23.730 回答