2012-11-12 26 views
0

我有两个php页面,一个是创建表格,另一个是创建图表。我的index.html文件应该调用它们,并且在点击图像时在主页上显示表格和图表。我已经使用这个代码显示两个href文件的一个区域标签

<div id="upload_target" ></div> 
<div id="upload_target2" ></div> 


<img src="image.png" alt="hello" usemap="#use" > 
<map name="use"> 
    <area shape="poly" coords="..." href="table.html" target="upload_target"> 
    <area shape="poly" coords="..." href="graph.html" target="upload_target2"> 
</map> 

所以当上area_1表用户点击“upload_target”显示,当他点击area_2,它在部分“upload_target2”所示。

但我想只是对他们俩的一个区域标签,所以当他在图像点击既可以显示出一些这样的事:

<img src="image.png" alt="hello" usemap="#use" > 
    <map name="use"> 
     <area shape="poly" coords="..." href="table.html" target="upload_target" href="graph.html" target="upload_target2"> 

    </map> 

有没有办法做到这一点?

+0

使用Ajax?没有它,你会得到一个单一的请求。 –

+0

@Dave Newton我使用Ajax在graph.php文件中显示表格,我应该如何在这里使用它? –

+0

我不确定我是否理解100%。当用户点击区域标签时,您希望将href源码加载到2个单独的元素中?那是你在找什么? – Kyle

回答

1

不幸的是,属性在HTML元素上必须是唯一的。您可以通过area元素上的onclick事件来完成此操作。

例如,你可以尝试下面的HTML:

<div id="upload_target1"></div> 
<div id="upload_target2"></div> 
<img src="image.png" alt="hello" usemap="#use" /> 
    <map name="use"> 
     <area shape="poly" coords="..." target1="table.html" target2="graph.html" onclick="return loadContent(this);" /> 
    </map> 

使用JavaScript函数:

function loadContent(ele) { 
    var target1 = ele.getAttribute('target1'), 
     target2 = ele.getAttribute('target2'); 
    //Make 2 AJAX requests to load the information 
    //If you are using jQuery, it is as simple as 
    $('#upload_target1').load(target1); 
    $('#upload_target2').load(target2); 
    return false; //Prevent the default action from happening 
} 

希望这有助于。

+0

您是否能够使用此功能来处理它? – Kyle

相关问题