此处将为大家介绍关于javascript-在锚定标记的点击事件监听器上为href添加void(0)和“返回false”有什么作用?的详细内容,此外,我们还将为您介绍关于href=“javascript
此处将为大家介绍关于javascript-在锚定标记的点击事件监听器上为href添加void(0)和“返回false”有什么作用?的详细内容,此外,我们还将为您介绍关于href=“javascript:void (0);” 和 href="void (change_code (this));"、javascript – Facebook Send-To-Messenger事件监听器、javascript – gmap3删除事件监听器、javascript – iframe和事件监听器的有用信息。
本文目录一览:- javascript-在锚定标记的点击事件监听器上为href添加void(0)和“返回false”有什么作用?
- href=“javascript:void (0);” 和 href="void (change_code (this));"
- javascript – Facebook Send-To-Messenger事件监听器
- javascript – gmap3删除事件监听器
- javascript – iframe和事件监听器
javascript-在锚定标记的点击事件监听器上为href添加void(0)和“返回false”有什么作用?
这个问题已经在这里有了答案: > Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”? 53个
如下所示对锚标记的累积影响是什么:
/**
* This function will create a popup iFrame (not a complete function)
*/
function CreateIframe() {
// This is just a sample and not complete code
var iframe = document.createElement('iframe');
// Initialize and create iFrame and popup iFrame
}
<a href="javascript:void(0)" onclick="CreateIframe();return false;" >Click here!</a>
解决方法:
关于void(0):
由@rahul在What does “javascript:void(0)” mean?中定义
The void operator evaluates the given expression and then returns undefined.
The void operator is often used merely to obtain the undefined primitive value, usually using “void(0)” (which is equivalent to “void 0”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).
“您之所以要使用链接的href这样做是因为,通常,一个javascript:URL会将浏览器重定向到评估该JavaScript的结果的纯文本版本.但是,如果结果未定义,则浏览器停留在同一页面上.void(0)只是可能评估为未定义的最小脚本.”
返回false:
就像event.preventDefault否定它一样.
如果您调用类似的函数:
<button type="submit" onclick="return some_function();"></button>
some_function返回false;如果您调用提交,则提交不会发生..但是,调用提交时,返回true将继续提交.
就您而言,单击链接不会重定向您.
href=“javascript:void (0);” 和 href="void (change_code (this));"
1、href = “javascript:void(0);”
1) javascript: 是伪协议,表示 url 的内容通过 javascript 执行。
void(0)表示不作任何操作,防止链接跳转到其他页面;void()操作符指定超级链接。
是为了保留链接的样式,不让链接执行实际操作,具体的操作交给 click 事件。
2) 当 href 不为空时,a 就是超链接;当 href 为空时,a 就是锚链接,它仍会跳到本页的页眉去。
2、href = “javascript:void(change_code(this));”
javascript – Facebook Send-To-Messenger事件监听器
参考:https://developers.facebook.com/docs/messenger-platform/plugin-reference/send-to-messenger#event
工作守则:
FB.Event.subscribe('send_to_messenger',function(e) { // callback for events triggered by the plugin console.log('inside the send_to_messenger'); window.top.location = 'http://google.com'; });
这将启动console.log和重定向,但我想要做的是当用户单击按钮并使用send_to_messener按钮触发选择时执行某些操作.
所以我试过了
FB.Event.subscribe('clicked',function(e) { // callback for events triggered by the plugin console.log('user clicked button'); window.top.location = 'http://google.com'; });
—也—
FB.Event.subscribe('send_to_messenger',function(e) { FB.Event.subscribe('clicked',function(e) { // callback for events triggered by the plugin console.log('user clicked button'); window.top.location = 'http://google.com'; }});
再一次,没有任何效果 – 如果有人有一个可以指向正确方向的线索,我会很感激..谢谢!!
解决方法
if (response.is_after_optin == true ){ // do something }
javascript – gmap3删除事件监听器
我想删除点击添加的事件监听器:
var events = {
click: function () {
// crazy stuff here :- )
}
};
$(where).gmap3(
{
events: events
}
);
需要类似的东西:
$(where).gmap3().removeEventListener('click');
解决方法:
没有意识到gmap3是一个包装库.我删除重复的评论.
浏览gmaps3文档时,我没有看到任何特定的删除具有库函数的侦听器,但您可以通过操作获取标记:’get’然后清除侦听器.
这是一个从文档中改变的示例.我在标记中添加了名称和标记属性,在此脚本的末尾,我从标记中删除了鼠标悬停监听器:标记为“2”.由于某种原因,这个库变化无常,并且想要name和tag属性来查找标记.
$('#test').gmap3({
action: 'init',
options: {
center: [46.578498, 2.457275],
zoom: 5
}
}, {
action: 'addMarkers',
markers: [
{
name : 'marker',
tag: '1',
lat: 48.8620722,
lng: 2.352047,
data: 'Paris !'},
{
name : 'marker',
tag: '2',
lat: 46.59433,
lng: 0.342236,
data: 'Poitiers : great city !'},
{
name : 'marker',
tag: '3',
lat: 42.704931,
lng: 2.894697,
data: 'Perpignan ! GO USAP !'}
],
marker: {
options: {
draggable: false
},
events: {
mouSEOver: function(marker, event, data) {
var map = $(this).gmap3('get'),
infowindow = $(this).gmap3({
action: 'get',
name: 'infowindow'
});
if (infowindow) {
infowindow.open(map, marker);
infowindow.setContent(data);
} else {
$(this).gmap3({
action: 'addinfowindow',
anchor: marker,
options: {
content: data
}
});
}
},
mouSEOut: function() {
var infowindow = $(this).gmap3({
action: 'get',
name: 'infowindow'
});
if (infowindow) {
infowindow.close();
}
}
}
}
});
//get the marker by name and tag
var mark = $('#test').gmap3({
action: 'get',
name:'marker',
tag: '2'
});
//remove the event listener
google.maps.event.clearListeners(mark, 'mouSEOver');
以下是此脚本工作的示例:http://jsfiddle.net/5GcP7/.中间标记在鼠标悬停时不会打开信息窗口.
javascript – iframe和事件监听器
大家好日子.
考虑一个包含iframe的页面. iframe源位于另一个域中.
我对两件事感兴趣:
>我可以在iframe中创建一个事件监听器来监听父窗口中发生的事件(并在iframe中运行一个函数)吗?
>我可以在父窗口中创建一个事件监听器来监听iframe中发生的事件(并在父窗口中运行一个函数)吗?
您可能想看一下这篇关于Cross-Domain Communication with IFrames的深入文章.它讨论了您能做什么和不能做什么,并提供了一些替代方案,如window.postMessage
今天关于javascript-在锚定标记的点击事件监听器上为href添加void(0)和“返回false”有什么作用?的讲解已经结束,谢谢您的阅读,如果想了解更多关于href=“javascript:void (0);” 和 href="void (change_code (this));"、javascript – Facebook Send-To-Messenger事件监听器、javascript – gmap3删除事件监听器、javascript – iframe和事件监听器的相关知识,请在本站搜索。
本文标签: