在 HTML 中,
<a href="some_url"> Contact Seller </a>
在 Cakephp 中,
<?php echo $this->Html->link('Contact Seller', array('controller'=>'pages', 'action'=>'contactseller', 'full_base'=>true)); ?>
但是我在将以下 html 转换为 Cakephp 时遇到了问题:
<a href="some_url" onClick="return popup(this, 'popup_name')">my popup</a>
下面是一个弹出javascript方法:
function popup(mylink, windowname) {
if (! window.focus)
return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
如何将 html 转换为 Cakephp?
<a href="some_url" onClick="return popup(this, 'popup_name')">my popup</a>
提前致谢。 :)
最佳答案
<a href="some_url" onClick="return popup(this, 'popup_name')">my popup</a>
将在 CakePHP 中转换为:
$this->Html->link('my popup', 'some_url', ['onclick' => 'return popup(this, "popup_name")']);
仅供引用,您可以将任何属性放在 link() 方法的第三个参数中。关于 creating links 的文档非常广泛并提供了示例。
关于javascript - Cakephp:如何在链接中调用javascript函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43196260/