2011-02-02 24 views
3

我從OpenLayer(JavaScript映射庫)使用OpenLayer.Popup.FramedCloud。在彈出式構造函數中有 有一個名爲contentHTML的參數。 我放在那裏的HTML按鈕,點擊數事件:OpenLayer.Popup.FramedCloud中無響應的onclick事件

contentHTML = "<button type='button' onclick='alert()'>Hello</button>"; 

從某些原因,按鍵並沒有點擊響應。 爲什麼?有沒有解決方案?

也許這是因爲網頁上傳到Winform WebBrowser? 我注意到,當我用普通的瀏覽器(鉻)上傳頁面時,一切正常 ,但不是在Winform WebBrowser中。

完全彈出對象:

 var lonlat = new OpenLayers.LonLat(lon, lat); 
     var size = new OpenLayers.Size(300,200) 
     var htmlString = "<button type='button' onclick='alert()'>Hello</button>"; 
    popup = new OpenLayers.Popup.FramedCloud("popup", 
               lonlat, 
               size, 
               htmlString,     
               anchor=null, 
               closeButtonX =false);   
     popup.id = callId; 
     g_waze_map.map.addPopup(popup); 

非常感謝。

+0

你可以上傳一個例子到http://JSFiddle.net? – 2011-02-06 16:02:14

回答

3

那麼,我正在開發和使用OpenLayers.Popup.FramedCloud並且工作正常(即使使用您的contentHTML)。這裏是我的代碼:

// i.e. x = 100, y = 300; 

var popup = new OpenLayers.Popup.FramedCloud(
    "getfeature", 
    map.getLonLatFromPixel(new OpenLayers.Pixel(x,y)), 
    new OpenLayers.Size(300,200), 
    "<button type='button' onclick='alert()'>Hello</button>", 
    null, 
    true 
); 
popup.autoSize = false; 
map.addPopup(popup); 

彈出窗口會自動打開並顯示我的按鈕。當我點擊它時,會顯示一條警告,並顯示文字'undefined'。

+0

對不起,無法正常工作 – 2011-02-05 15:40:08