framework7不会打开javascript链接到锚标记

时间:2016-11-26 22:43:17

标签: javascript hyperlink anchor html-framework-7

我有一个按钮可以激活clickEvent()onclick功能。我希望只有在不满足条件时才能打开新的锚链接。

createClick() {
    if (condition) {
     //something
    } else {
    window.open("#about", "_self");
}

但是,我无法使用我的javascript打开链接。它只适用于我在链接中添加一个href,这不是我想要的,因为它不受我的条件约束。

<button onclick="clickEvent();" href="#about" class="item-link button button-big button-fill color-orange">GO!</button>

我已经允许在我的config.xml中访问href =“*”,所以我不认为这是问题所在。

由于

1 个答案:

答案 0 :(得分:1)

只需2种方法即可:

1。把你的条件放在链接上:

因此链接不会打开,直到条件为True。

function createClick() {
  if (1==2) {
  	return true;
  } else {
    return false;
  }
}
<a href="http://google.com" onclick="return createClick()">Go to Google</a>

2。如果您的目标页面是framework7模板页面,您只需调用:

mainView.router.loadPage(url)

在路由器API文档页面中了解更多信息:http://framework7.io/docs/router-api.html

我希望这会有所帮助。

相关问题