【问题标题】:What's wrong with my button and the link isn't working? [closed]我的按钮有什么问题并且链接不起作用? [关闭]
【发布时间】:2016-10-02 09:46:00
【问题描述】:

它工作得很好,但是……嗯……我不知道我做了什么……

<form>
<span style="font-family:arial,helvetica,sans-serif;
font-size:24px;font-weight:bold;">
   <input onclick="window.location.href='
     https://trehebe.blogspot.gr/p/online-paraggelia.html'
     target:_blank" style="background:rgb(153, 0, 255); border-radius:20px; 
     border:1px solid rgb(217, 217, 217); 
     box-shadow:rgb (153, 153, 153) 6px 6px 5px; color:#ffffff;
     cursor:pointer; font-weight:bold; padding:10px; width:100px;" 
     type="button" value="Order" />
</span>
</form>

【问题讨论】:

  • 您为什么认为有问题?请阅读How to Ask 一个正确的问题。
  • &lt;input onclick="window.location.href='https://trehebe.blogspot.gr/p/online-paraggelia.html'" target="_blank" style="background:rgb(153, 0, 255); border-radius:20px; border:1px solid rgb(217, 217, 217); box-shadow:rgb (153, 153, 153) 6px 6px 5px; color:#ffffff; cursor:pointer; font-weight:bold; padding:10px; width:100px;" type="button" value="Order" /&gt; `
  • 您为什么使用&lt;input&gt; 作为链接?只需使用正确的&lt;a&gt; 标签即可。
  • 当@MikeC 询问你为什么使用input 标签时,target 属性仅适用于&lt;a&gt; 标签

标签: javascript html button


【解决方案1】:

就用这个吧:

onclick="window.location.href='https://trehebe.blogspot.gr/p/online-paraggelia.html';" target="_blank"

编辑:

作为一个完整的代码:

<form><span style="font-family:arial,helvetica,sans-serif; font-size:24px;  font-weight:bold;"><input onclick="window.location.href='https://trehebe.blogspot.gr/p/online-paraggelia.html;'" target="_blank" style="background:rgb(153, 0, 255); border-radius:20px; border:1px solid rgb(217, 217, 217); box-shadow:rgb (153, 153, 153) 6px 6px 5px; color:#ffffff; cursor:pointer; font-weight:bold; padding:10px; width:100px;" type="button" value="Order" /></span></form>

另一个编辑(解释):

错误在于onclick 属性 OP 没有用双引号正确关闭它。所以我只是添加了一个分号和一个双引号来结束语句。

target 属性格式错误,因为它最初以 target:"_blank" 出现。在 HTML 属性中使用等号 target="_blank"

为了证明这里是fiddle

【讨论】:

  • 你做了什么改变,为什么?这看起来不像完整的代码。
  • @FelixKling 我刚刚更改了 onclicktarget 属性,因为它们都是格式错误的。
  • 您可能想解释一下究竟是什么错误。此外,没有完整的示例也没关系,但这需要您解释您修复了哪个部分(以及为什么)。 “只需使用这个”可以很容易地解释为用您的(不完整的)示例替换整个代码。但是,如果您说类似:“href 属性的值无效,...”那么它就更清楚了...
  • @FelixKling 那里我已经添加了更详细的解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 1970-01-01
  • 2014-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-21
相关资源
最近更新 更多