百度地图信息框增加按钮事件

1.这是定义信息框代码

function CreateOpts(content) {
            var opts = {
                width : 350,
                height : 238,
                title : "<strong>设备信息:</strong><br><br>"
            }
content = '<div id="LoginBox">'
                        + '<div class="row" style="width: 300px;height: 35px;margin-top:-10px;">名字: </div>'
                        + '<div class="row" style="width: 300px;height: 35px;">覆盖范围: </div>'
                        + '<div class="row" style="width: 300px;height: 35px;">安装地址: </div>'
                        + '<div class="row" style="width: 300px;height: 35px;">一线维护人:</div>'
                        + '<div class="row">'
                        + '<input οnclick="quxiao(this)" type="button" id="btn1" value="取消" style="width: 100px;height:30px;margin-top: 20px;margin-left: 120px;">'
                        + '</div></div>';
            var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象    第一个参数为内容            
            marker.addEventListener("click", function() {
                map.openInfoWindow(infoWindow, map.getCenter()); // 打开信息窗口
            });

        }


function quxiao(name) {
            name1=$(name).parent().parent().children(':first').next().next().html();
            var arr=name1.split(':');
            window.location.href="${pageContext.request.contextPath }/device/quxiao.do?name="+encodeURIComponent(encodeURIComponent(arr[1],'UTF-8'),'UTF-8');
        }

这种方式可以正常运行。事件必须要立刻绑定,如红色部分。如果按照id或者class来查会找不到。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
可以使用百度地图API提供的信息窗口对象(BMap.InfoWindow)来创建带有关闭按钮的标记点信息,并在关闭按钮的点击事件中调用信息窗口对象的close()方法来关闭窗口。具体实现如下: 1. 创建信息窗口对象时,设置enableCloseOnClick属性为false,这样点击信息窗口的内容区域不会关闭窗口。 2. 在信息窗口的内容区域中添加一个关闭按钮,可以使用HTML代码创建一个按钮元素,例如: ``` <div><a href="javascript:void(0);" class="close-btn" onclick="closeInfoWindow()">关闭</a></div> ``` 3. 在JavaScript代码中定义closeInfoWindow()函数,该函数在按钮点击事件中调用信息窗口对象的close()方法来关闭窗口。例如: ``` function closeInfoWindow() { infoWindow.close(); } ``` 完整代码示例如下: ``` // 创建标记点 var point = new BMap.Point(116.404, 39.915); var marker = new BMap.Marker(point); // 创建信息窗口 var content = '<div>这是一个标记点</div>' + '<div><a href="javascript:void(0);" class="close-btn" onclick="closeInfoWindow()">关闭</a></div>'; var infoWindow = new BMap.InfoWindow(content, { enableCloseOnClick: false // 禁止点击内容区域关闭窗口 }); // 绑定标记点点击事件 marker.addEventListener('click', function() { map.openInfoWindow(infoWindow, point); // 显示信息窗口 }); // 关闭信息窗口函数 function closeInfoWindow() { infoWindow.close(); } ``` 注意:以上代码只是示例,具体实现需要根据自己的需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值