我想讓彈出式插件在Javascript字符串內工作。所以當用戶鼠標懸停geolocation
時,彈出窗口就會出現,並且在鼠標被拿走時消失。在Javascript字符串中使用Bootstrap的彈出式插件
<script type="text/javascript">
$('#directions-panel').text("We can't give you directions to our office as you don't have", <a href="#" rel="popover" data-content="Some content..." data-original-title="Some title..." > geolocation </a> " enabled on your browser. Enable geolocation and try again. The map above will show you where our office is located.");
</script>
而且使用這樣的調用?
$("[rel=popover]")
.popover({
offset: 10
})
.mouseover(function(e) {
e.preventDefault()
})
我知道這是有點全地方,但我已經四處搜尋,找不到任何類似於我想做的事情。我確信它可以完成,任何人都指向正確的方向?
編輯:
我知道有聯繫頁面如下:
<div id="directions-panel">
<div id="directions-error-message" style="visibility:hidden">
We can't give you directions to our office as you don't have <a href="#" id="geoloc-popover" rel="popover" data-content="Some content..." data-original-title="Some title..." > geolocation </a> enabled on your browser. Enable geolocation and try again. The map above will show you where our office is located.
</div>
</div>
和DIV directions-error-message
變得可見,當下面的JS function failure()
火災:
function failure() {
alert("Your browser does not have geolocation enabled so we can't give you directions to our office. Enable geolocation and try again, or consult the map for our address.");
$("#directions-error-message").css({
visibility: 'visible'
});
var destMapOptions = {
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(ourLocation.lat, ourLocation.lng)
}
map = new google.maps.Map(document.getElementById("map-canvas"), destMapOptions);
marker = new google.maps.Marker({
position: ourLatLng,
map: map,
draggable: false,
animation: google.maps.Animation.DROP,
title: "Hello"
});
google.maps.event.addListener(marker, 'click', toggleBounce);
}
$(function() {
$('#directions-error-message').popover({
selector: '[rel="popover"]',
trigger: 'hover'
});
})
是否有辦法只需在directions-error-message
DIV觸發彈出窗口中的「地理定位」?
現在你所要做的就是將'$('#directions-error-message')'改爲'$('#geoloc-popover')'。您正在使用ID#directions-error-message而不是僅鏈接將彈出式觸發器設置爲整個div。 –
仍似乎沒有工作。我把觸發器放在'失敗'裏面,但仍然沒有區別。我想通過ID選擇錨點?那會不會像'$('a [id =「#geoloc-popover」]')'? – MattSull
您不希望失敗功能中的觸發器。而且任何標籤的id都可以用'#theidvalue'引用,所以你不需要''[id =「#geoloc-popover」]'。嘗試從彈出功能中刪除選擇器行。應該是'$(function(){$('#geoloc-popover')。popover({trigger:'hover'});})'。 –