2014-10-29 43 views
0

我有一个HTML页面,按钮A,按钮B.使用JavaScript或iframe同步两个按钮

在第一加载的页面两个按钮,这两个按钮具有“图像”,图像1。

当我点击按钮A时,图像变为图像-2,但按钮B保持不变(图像-1)。当我点击按钮B时,图像变为图像-2,但按钮A保持不变(图像-1)。

我喜欢它,所以如果你点击'任一按钮'(A或B),那么BOTH的按钮图像就会变成图像2。

我目前在'iframe'中有两个按钮,所以按钮是分离的。

你能推荐一个javascript来做到这一点吗? (或者,是否有办法在单个页面上“同步”iframe按钮?)

+1

后一些代码,并解释为什么你使用的I帧。一般来说,只是选择要更改的页面元素(例如,通过元素ID)并应用更改(显然您已经知道该如何执行)。 – 2014-10-29 00:12:02

+0

这是代码。 的iframe中代码: < “?boost1.php $网址” IFRAME SRC => - (boost1.php) ”; ?> - (boost2.php): <?php $ boosturl = trim($ _ POST ['boosturl']); //数据更新 echo“ ”; ?> – user2566281 2014-10-29 06:07:50

+0

我需要将它转换为javascript,因为我在同一页上有iframe 2位置。所以,当我点击一个iframe按钮时,它会变成第二个按钮。但是第二个iframe按钮并不是我想要改变的,除了执行php功能。我想我最好在javascript中这样做,但如果您有任何想法,需要帮助。 – user2566281 2014-10-29 06:16:28

回答

0

下面是一个小示例,向您展示如何使用JavaScript同步两个按钮。让我知道你是否需要一些解释。 。 。

function sync1(){ 
 
    
 
    var button1 = document.getElementById('button1'); 
 
    var button2 = document.getElementById('button2'); 
 
    
 
    button1.style.background = 'red'; 
 
    button1.style.color = 'white'; 
 
    
 
    button2.style.background = 'red'; 
 
    button2.style.color = 'white'; 
 
    
 
} 
 

 
function sync2(){ 
 
    
 
    var button1 = document.getElementById('button1'); 
 
    var button2 = document.getElementById('button2'); 
 
    
 
    button1.style.background = 'blue'; 
 
    button1.style.color = 'white'; 
 
    
 
    button2.style.background = 'blue'; 
 
    button2.style.color = 'white'; 
 
    
 
}
<button class="1" onclick="sync1()" id="button1">I can change the other button!</button> 
 
<br /><br /> 
 
<button class="1" onclick="sync2()" id="button2">Me too!</button>

+0

这有很大的帮助,我们还想在这里做更多的事情(如果您有任何想法或建议)。 我们需要任一按钮来启动一个php脚本,并且随着脚本启动,'两个'按钮都会改变颜色。 另外,我们对每个按钮都有'img src'。所以,对于两个按钮他们都有一个图像,如果点击,两个按钮都会转到另一个图像。 无论如何,你可以给任何帮助表示赞赏!谢谢。 – user2566281 2014-10-29 05:46:16