如何使用淘汰赛数据绑定在新选项卡中打开按钮链接 [英] How to open button link in new tab using knockout data-bind
问题描述
我正在尝试使用按钮将链接打开到新标签页.问题是我正在使用数据绑定属性:href 并使用 target="_blank" 不起作用,因为目标函数要求 href 不在数据绑定中.
I am trying to use a button to open a link into a new tab. The issue is that I am using a data-bind attr: href and using target="_blank" does not work because the target function requires the href not to be in a data-bind.
我在不使用数据绑定时让它工作,但是在两个页面之间发送信息需要数据绑定.
I have gotten it to work when not using a data-bind, but a data-bind is necessary for sending information between the two pages.
<a data-bind="attr: {href: '@Url.Action("Data", "Report")/?serialNumber='+SN()}" class="btn btn-警告 createNew">查看报告
此代码是工作代码,但在同一选项卡中打开.
This code is the working code but opens in the same tab.
当我在数据绑定之外添加 target="_blank" 时,我收到一条错误消息,指出目标函数需要使用 href.
When I add target="_blank" outside of the data-bind, I get an error saying that the target function requires href to be used.
当我在 href 之后将 target: "_blank" 添加到数据绑定中时,它不会做任何事情并且按钮不再起作用.
When I add target: "_blank" into the data-bind after the href, it does not do anything and the button no longer works.
目前,该按钮可以工作并带入我需要的信息,我只是希望它在新标签页中打开.
Currently, the button works and brings in the information I need, I just want it to open into a new tab.
推荐答案
你可以简单地这样做:
<a data-bind="attr: {href: '@Url.Action("Data", "Report")/?serialNumber='+SN()}" class="btn btn-warning createNew" target="_blank"> View Report </a>
您可以忽略 HTML 验证错误,因为验证器不会——也不能——知道动态添加的 href
属性.这不是问题.
You can ignore the HTML validation error since the validator does not - and cannot - know about the dynamically added href
attribute. It's not a problem.
这篇关于如何使用淘汰赛数据绑定在新选项卡中打开按钮链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!