简体   繁体   English

显示/隐藏ajax? JavaScript切换

[英]show/hide ajax? javascript toggle

I'm looking for a wordpress plugin that hides to start with the when I click say an arrow image an ajax feature pops out with say a contact form inside and also another show hide feature at the bottom of the page to show and hide multiple divs. 我正在寻找一个wordpress插件,该插件会隐藏起来,当我单击说箭头图像时,弹出一个ajax功能,并在其中显示一个联系表单,并且在页面底部还显示另一个隐藏功能,以显示和隐藏多个div 。

Is there a plugin that can do all this? 有没有可以完成所有这些工作的插件?

My pages have to be editable for my client so it is impossible for me to build this into the theme. 我的页面必须针对我的客户是可编辑的,因此我无法将其构建到主题中。 The javascript function needs to be part of a page. javascript函数必须是页面的一部分。 I've found WP ShowHide Elements but this does not allow me to do it with multiple divs in the same placement. 我已经找到WP ShowHide Elements,但这不允许我在同一位置中对多个div进行处理。

Here's some of the script I'm using as allowed by the plugin in my pages 这是我页面中插件允许的一些脚本

    <p id="mytest">my text</p>
<p><a onclick="wp_showhide('mytest')" href="javascript:void(0);">my link</a></p>
<p id="new">new</p>
<p><a onclick="wp_showhide('new')" href="javascript:void(0);">new</a></p>

Thanks for your help Regards 感谢您的帮助

Judi 朱迪

PS http://wordpress.digitalnature.ro/mystique/ Please notice the sidebar on this website, this is what I'm trying to achive but within the main page content PS http://wordpress.digitalnature.ro/mystique/请注意此网站上的侧边栏,这是我试图实现的目标,但仍在主页内容之内

This short script works within a page but I want a swap div effect How can I use this to work with multipe divs? 这个简短的脚本可以在页面中使用,但是我需要一个swap div效果如何使用它来处理multipe div? - i'd like to change the visability of multiple divs all with the same space or div -我想更改所有具有相同空格或div的div的可见性

   <p><script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script></p>
<p><a onclick="toggle_visibility('foo');" href="#">Click here to toggle visibility of element #foo</a></p>
<div id="foo">This is foo</div>
<p><a onclick="toggle_visibility('too');" href="#">Click here to toggle visibility of element #too</a></p>
<div id="too">This is too</div>

I think I may have solved my own problem :) Would love to know whether anyone can modify it so the 1st div is already open when the page loads 我想我可能已经解决了我自己的问题:)很想知道是否有人可以对其进行修改,因此在页面加载时第一个div已经打开

<p><script type="text/javascript">
lastone='empty'; 
function showIt(lyr) 
{ 
if (lastone!='empty') lastone.style.display='none'; 
lastone=document.getElementById(lyr); 
lastone.style.display='block';
}
</script></p>
<p><a href="JavaScript:;" onClick="showIt('divID')">link</a></p>
<div id="divID" style="display: none;">content</div>
<p><a href="JavaScript:;" onClick="showIt('new')">link</a></p>
<div id="new" style="display: none;">content</div>

To answer your edit: can't you just remove the display:none style from the original div? 要回答您的编辑:您不能只从原始div中删除display:none样式吗?

If you need to do it in Javascript, chuck a showIt('divID'); 如果您需要用Java脚本执行此操作,请删除showIt('divID'); line in after your function. 在您的功能后排队。

To do it properly, add it into window.onload: 要正确执行此操作,请将其添加到window.onload中:

window.onload = showIt('divID');

Or more properly, have a function that enqueues into the onload ( like this ). 或更恰当地说,有一个可以加入onload的函数( 像这样 )。

Or probably best, use a framework :) 也许最好,使用框架 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM