PHP 中的 Tab 键操作?
我的页面上有这些类型的选项卡
Equ |税务 |平衡 |债务|资金| ETF |镀金.......
然后这些选项卡下面有空间。当用户单击这些选项卡时,与这些选项卡相对应的数据必须显示在该空间中,而不更改页面的 url。就像当我单击 Equ 时,其数据将显示在该空间中,如果我单击 Tax,则其数据将显示在该空间中将显示在同一空间中,就好像它已覆盖以前的数据一样。必须显示的数据是使用 php 计算的。 现在使用 php 或 javascript 最简单的方法是什么???
一些编码帮助将不胜感激。
编辑: 我知道这可以使用 javascript 来完成,但是必须显示的数据位于 php 变量中。现在如何将 php 变量分配给 javascript???
<script type="text/javascript">
function showhide(ref)
{
document.getElementById('mf').innerHTML= HERE I WANT A PHP VARIABLE;
}
</script>
我如何在 onclick 事件中发送我的 pfp 变量,以便它们可以在函数中使用???
i have these kind of tabs on my page
Equ | Tax | Balanced | Debt | Funds | ETF | Gilt .......
and then there's space below these tabs. When user clicks on these tabs then a data corresponding to these tabs has to be displayed in that space without changing the url of the page.Like when i click Equ then its data will be displayed in that space ,if i click tax then its data will be displayed in that same space as if it has overwritten the previous data.The data that has to e shown is calculated using php.
Now what is the easiest way to do so using php or javascript ???
some coding help would be appreciated here .
EDIT:
see i know this can be done using javascript but the data that has to be shown is in php variable .Now how to assign a php variable to javascript????
<script type="text/javascript">
function showhide(ref)
{
document.getElementById('mf').innerHTML= HERE I WANT A PHP VARIABLE;
}
</script>
how can i send my pfp variables in onclick event so that they can be used in the function???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 CSS 或/和 Javascript 来帮助您实现这一目的。
仅使用 CSS 的选项卡示例:
http://edeverett.co.uk/experiments/css_only_tabs.html
使用 Javascript 的选项卡示例:
http://jqueryui.com/demos/tabs/
编辑
作为对您的编辑的回复:
要在服务器端同步执行所有操作,您可以将计算结果注入到 JavaScript 中:
更好的做法是使用 AJAX。
You may use CSS or/and Javascript to help you do the trick.
Example of tabs using CSS only:
http://edeverett.co.uk/experiments/css_only_tabs.html
Example of tabs using Javascript:
http://jqueryui.com/demos/tabs/
Edit
As reply to your edit:
To perform everything on server-side synchronously, you can inject calculated result into your javascript:
A better practise would be to use AJAX.
这实际上很容易。您不需要在单击选项卡时动态加载数据。您可以在页面加载时一次性加载所有数据,然后根据需要显示/隐藏。
一个简单的例子...
假设 equ 是默认内容。当页面加载时,
使用 javascript(推荐使用 jquery)隐藏除 equ 之外的所有其他 div(使用 css 或最好是 javascript)。单击选项卡时隐藏所有内容,然后显示该选项卡内容。
代码并不意味着可以复制和粘贴,我作为示例快速输入了它
It's actually pretty easy. You dont need to load the data dynamically on the tab clicks. you can load the data all at once when the page loads then just show/hide as needed.
an easy example...
let's say equ is the default content. when the page loads hide all other divs besides equ (using css or preferably javascript)
using javascript (jquery recommended) when a tab is clicked hide all content and then show that tabs content.
code isn't meant ot be copy and pasted, i typed it out quickly as an example
您必须使用 ajax
您可以使用一些库,例如 xajax、mootools 或 jquery 。
更新:
mootools 的示例:
首先创建单独的 php 文件,根据选项卡返回文本(createContent.php)
然后在 javascript:
在 html 中为具有该功能的选项卡添加 onclick :
You have to use ajax
You can use some libraries like xajax, mootools or jquery.
Upd:
Example with mootools:
first create separate php file, that returns text acording to tab(createContent.php)
then in javascript:
in html add onclick for tabs with that function:
显示行为将是客户端的事情,因为它是发生在浏览器上的事情(某些逻辑)。如前所述,您必须使用 javascript/css 来完成此操作。
在编码帮助方面,您可能会发现这很有帮助:
http://stilbuero.de/jquery/tabs_3/
编辑
所以,如果你想在那里放置一个 php 变量,这就是你要做的,并将其设为“.php”页面:
当然,这假设你在渲染页面之前已经计算了变量。如果变量的值取决于页面上的某些操作(例如,在文本框中输入一些文本并单击按钮后 - 就像搜索框一样),则必须使用 AJAX。您可以通过对 php 页面执行 GET 请求或 POST 请求来实现此目的,然后显示该页面的内容。我上面发布的链接有一个 AJAX 选项卡的示例,您可以看一下。
Display behaviour would be a client-side thing, since it is something (some logic) that happens on the browser. As previously stated you would have to use javascript/css to do it.
In terms of coding help, you might find this helpful:
http://stilbuero.de/jquery/tabs_3/
EDIT
So, if you want to put a php variable there, this is what you do and make this a ".php" page:
Of course this assumes that you have the variable computed before rendering the page. If the variable's value depends on some action on the page (for e.g., after entering some text in a textbox and a button is clicked - like a search box), you would have to use AJAX for that. You would do that by doing a GET request of POST request to a php page and then display the content from that page. The link I posted above has an example for AJAX tabs, you could take a look at that.