【问题标题】:Linking a javascript pop-up function to a hyperlink-tag将 javascript 弹出功能链接到超链接标签
【发布时间】:2015-12-07 15:39:20
【问题描述】:

我是新来的,所以如果我的问题已经得到解答,请不要跳到我的喉咙里;不过我一直在寻找答案。

好的,这就是我需要做的: 在我忙的网站上,有一个外部 css 修改的超链接标签,看起来像一个按钮。单击后,它将用户重定向到注册页面。 超链接元素的html和css:

.button_promo {
  background: transparent none repeat scroll 0 0;
  border: 3px solid #ef4923;
  border-radius: 6px;
  color: #787878;
  cursor: pointer;
  display: inline-block;
  font-family: Vag, helvetica, arial;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 1px;
  line-height: 21px;
  outline: 0 none;
  padding: 7px 25px;
  position: relative;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.2s ease-in-out 0s, color 0.2s ease-in-out 0s, border-color 0.2s ease-in-out 0s;
  width: 200px;
}
<ul>
  <li><a href="signup.html" class="button_promo">Sign up</a>
  </li>
</ul>

我需要做的是改变元素的功能,这样当用户点击它时,它会弹出一个弹出窗口。但是,这是我需要使用的弹窗功能代码:

(function() {
  var e = document.createElement('script');
  e.type = 'text/javascript';
  e.async = true;
  e.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://btn.createsend1.com/js/sb.min.js?v=3';
  e.className = 'createsend-script';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(e, s);
})
();
<div class="createsend-button" style="height:27px;display:inline-block;" data-listid="i/41/44A/73A/85038CAF46C6F93F">

</div>

弹出功能代码创建它自己的按钮,但我不希望这样。我需要将它链接到超链接标签,而不改变链接的样式。因此,我需要该功能不是创建它自己的按钮,而是执行单击链接后弹出所需弹出窗口的实际动作。

有什么想法吗?

【问题讨论】:

  • 你可以使用模态窗口吗?

标签: javascript jquery html css hyperlink


【解决方案1】:

不是真正的解决方案,而是一种快速而肮脏的解决方法,即隐藏创建的按钮并触发单击按钮以单击弹出按钮。

我不建议这样做,但加载的脚本很难理解(对我来说)。

类似的东西应该可以工作:

document.querySelector('.botton_promo').addEventListener("click", function() {
  document.querySelector('.createsend-button').click();
});
.createsend-button {
  display: none;
}

我建议给你的按钮一个 ID

【讨论】:

    【解决方案2】:

    只需适当地更改您的链接/按钮。你可以删除那个js函数。您不必使用它。

    <a href="signup.html" class="button_promo">Sign up</a>
    

    <a href="javascript:void(0)" class="button_promo" onclick="window.open("http://www.somelink.com", "_blank", "location=1,status=1,scrollbars=1, width=400,height=400")">Sign up</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 2018-01-30
      • 2014-10-15
      • 1970-01-01
      相关资源
      最近更新 更多