frameSet中,某个iframe调用其他iframe的js函数及获取对象

先看index.jsp

<frameset rows="78,*" cols="*" frameborder="no" border="0" framespacing="0">
  <frame src="head.jsp" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame">
  <frameset cols="*,350" frameborder="no" border="0" framespacing="0">
    <frame src="map.jsp" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame">
    <frame src="info.jsp" name="mainFrame" id="mainFrame" title="mainFrame">
  </frameset>
</frameset>

 

在head.jsp中有如下申明,一个搜索框,搜索的内容在另外一个frame中,注意onclick的值的写法。

<div class="itopmiddle3">
                       <input type="text" id="taxiNum"  class="itopmiddle_search" size="18"/>
               </div>
               <div class="itopmiddle4">
                       <input name="" type="button" onclick="window.parent.frames['leftFrame'].search()"  class="itopmiddle_submit" value=""/>
               </div>

在map.jsp的search方法的写法是:

function search(){
    var searchKey = $("#taxiNum",window.parent.frames['topFrame'].document).val();
    if(searchKey==""){
        alert("请输入搜索项!");
    }
    var array = new Array();
    array = map.getOverlays();
    for(var i=0;i<array.length;i++){
        var over = array[i];
        var titalString = over.getTitle();
        var title_array = new Array();
        title_array = titalString.split(":");
        var index = title_array[1].indexOf(",");
        var taxiNum = title_array[1].substring(0,index);
        if(searchKey==taxiNum){
            map.centerAndZoom(over.getPosition(),18);
        }
    }
}

这样就能获取到值和调用方法了!刚用百度api,还不是很熟悉,上一张图吧!

上面的搜索框就能搜索到下面地图中的数据了!

posted on 2012-10-26 17:57  cydyhty  阅读(512)  评论(0编辑  收藏  举报

导航