0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

🍰【CakePHP2】テンプレートにjavascript呼び出しのみのボタンを設置

Last updated at Posted at 2019-11-29

環境

PHP 7.2.21
CakePHP 2.10.18

内容

CakePHPのHTML機能でjsを呼び出す
デフォでリンクになるがページ移動はしたくない

やりたいこと

jsを呼び出すだけのボタンを設置

やったこと

test.ctp

<?php echo $this->Html->link('click me', 'javascript:hoge();void(0)', ['class' => 'fuga']); ?>

// class無しの場合
<?php echo $this->Html->link('click me', 'javascript:hoge();void(0)'); ?>

<script>
    function hoge() {
        alert('HOGE');
    }
</script>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?