2013-06-24 112 views
0

我使用这个代码用JavaScript来改变包括路径:使用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; 
} 

但是,如何使用这一个提交按钮?

+0

什么是'#actionLink',以及如何获取包含PHP的页面? – adeneo

回答

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> 
0
$('button').onclick(function() { 
$(location).attr('href', 'www.example.com'); //redirect to www.example.com 
}); 
0

只需在HTML中完成。

<form method="GET" action="?page=whatever"> 
    <input type="submit" value="Click Me!" /> 
</form> 
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; 
} 

我希望这能有一定的帮助。