使用javascript更改包含路径

时间:2013-06-24 11:46:09

标签: php javascript html

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

但是如何使用submitbutton?

4 个答案:

答案 0 :(得分: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>

或者最后,隐藏的领域&amp; 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>

答案 1 :(得分:0)

$('button').onclick(function() {
$(location).attr('href', 'www.example.com'); //redirect to www.example.com
});

答案 2 :(得分:0)

只需在HTML中执行。

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

答案 3 :(得分: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;
 }

我希望这可以提供一些帮助。