简体   繁体   English

如何将我的价值添加到此按钮href

[英]How do I add my value to this button href

I want to add custom link that is stored in a value inside a php button. 我想添加自定义链接,该链接存储在php按钮内的值中。 How do I do it? 我该怎么做?

I am trying to get this sorted how ever its not doing it, it just returns nothing or sometimes returns the current page link instead. 我试图对此进行排序,但它什么也不做,它什么也不返回,或者有时返回当前页面链接。 I am looking towards adding my $lnk to this code in href section. 我希望将我的$ lnk添加到href部分中的此代码中。

This is what I have: 这就是我所拥有的:

echo '<input class="btnnn-class" type=btnnn-class onClick=location.href="" .$lnk value="Contact Buyer">';

Where $lnk is my link inside of it. $lnk是其中的链接。

There is several typos in your code : you did not open and/or close quotes when needed. 您的代码中有多种错别字:您在需要时没有打开和/或关闭引号。 You have too surround your classes with double quotes and your onClick value too. 您也可能在类中使用双引号和onClick值。 Inside it, the location href is a string too that should be inside quotes. 在其中, location href也是一个字符串,也应放在引号内。

Both php and javascript allow single and double quotes to delimitate a string, but you should use only double quotes for html attributes. php和javascript都允许使用单引号和双引号来分隔字符串,但是html属性应仅使用双引号。

So: 所以:

  • Use single quotes ' for the whole echo statement (but varaiables are not interpreted inside single quotes), 对于整个echo语句,请使用单引号' (但变量不会在单引号内解释),
  • Use double quotes " for the html attributes. html属性使用双引号"
  • Use single quotes ' for the javascript value, and escape it (becasue they are inside another php single quoted string). 使用单引号'作为javascript值,并对其进行转义(因为它们位于另一个php单引号字符串内)。

The code: 编码:

echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $url . '\'" value="Contact Buyer">' ;

Or use double quotes for php and espace the html attributes ones, the variable will be interpreted: 或对php使用双引号,对html属性使用espace,将对该变量进行解释:

echo "<input class=\"btnnn-class\" type=\"btnnn-class\" onClick=\"window.location.href=$url\" value=\"Contact Buyer\">" ;

Al Fonce told correct answer and described wel He forget one double quotes after $lnk . 阿尔·丰斯(Al Fonce)告诉了正确的答案,并描述了他在$ lnk之后忘了一个双引号。 '\\' '\\'

echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $lnk . '\'" value="Contact Buyer">' ;

Try this: 尝试这个:

echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'$lnk\'" value="Contact Buyer">' ;

Because of the quotes, you are facing the problem. 由于引号,您正面临问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM