2012-11-05 42 views
0

我想要做的就是转换与CakePHP的工作如下:如何在CakePHP中实现JavaScript onmouseover?

<a href="URL ADDRESS"><img src="URL OF THE FIRST IMAGE GOES HERE" onmouseover="this.src='URL OF THE SECOND IMAGE GOES HERE'" onmouseout="this.src='URL OF THE FIRST IMAGE GOES HERE'" /></a> 

我见到目前为止以下内容:

<?php echo $this->Html->image("animalhealth.png", array(
    "alt" => "Animal Health", 
    "onmouseover" => "this.src='animalhealthhover.png'", 
    "onmouseout" => "this.src='animalhealth.png'", 
    'url' => array('controller' => 'records', 'action' => 'index' 
    ) 
)); ?> 

的问题是onmouseover & onmouseout事件行。我需要告诉蛋糕以某种方式使用辅助方法,否则它只会选择没有图像。我不想将整个地址作为导航菜单,并且在不同位置会有多个应用程序实例。

回答

0

我已经设法构建了一个使用CSS的工作。

为按钮图标制作了自定义图像。

这是在视图/布局页面发生的事情:

<ul class="menu"> 
<li> 
         <div id="button_name"><?php 
        echo $this->Html->image("name_of_img.png", array(
         "alt" => "Animal Health", 
         'url' => array('controller' => 'controllerName', 'action' => 'index'))); 
        ?> 
<?php echo $this->Html->link(__('Link Text'), array('controller' => 'controllerName', 'action' => 'index')); ?> 
         </div> 
        </li> 
</ul> 

如果你不使用CakePHP,你可以做这样的在一个普通的HTML页面:

<ul class="menu"> 
<li> 
         <div id="button_name"><a href="/path/to/page.html"><img src="/path/to/img/imagename.png" alt="Animal Health" /></a><a href="/path/to/page.html">Animal Health</a> 
         </div> 
        </li> 
<ul> 

这使得无论是文字和图标可点击。

然后CSS:

.menu li {padding:0px; border: 0px; margin: 0px; list-style: none; 
      float: left; margin-left: 0px; display: block; height: 36px;} //remove any stlying and set up for the menu. 

#button_name{background-color: darkorange; 
       float: left; 
       margin-right: 5px; 
       margin-top: 1px; 
       margin-bottom: 0px; 
       padding: 1px 3px 1px 3px; 
       -webkit-border-radius: 5px 5px 0px 0px; 
       border-radius: 5px 5px 0px 0px; 
       border: 1px black; 
       text-align: right; 
       color: #6495ED; 
       font-weight: bold; 
       -webkit-transition: all 1000ms; 
       -moz-transition: all 1000ms; 
       -o-transition: all 1000ms; 
       -ms-transition: all 1000ms; 
       transition: all 1000ms;} 
#button_name a { 
    -webkit-transition: all 1000ms; 
    -moz-transition: all 1000ms; 
    -o-transition: all 1000ms; 
    -ms-transition: all 1000ms; 
    transition: all 1000ms; 
    font-weight: bold; 
    color: #6495ED; 
} 
    #button_name:hover 
{background-color: #6495ED;} 
    #button_name:hover a // VERY IMPORTANT see note 
{ 
     font-weight: bold; 
     color: darkorange;} 

这使得一个很好的按钮,2圆的上角。当您将鼠标悬停在任何位置时,背景和文字颜色会在彼此之间转换。即:文本从蓝色变为橙色,背景从橙色变为蓝色。

关于#button_name:hover a的注意事项a: 如果将其设置为“button_name a:hover”,则必须将其设置为指定的文本将保持与背景相同的颜色。

希望这会帮助别人。

仍然渴望听到有关使用JS做任何想法。

0
echo $html->link($this->Html->image("animalhealth.png", array("alt" => "Animal Health")), array('controller' => 'records', 'action' => 'index'),array("onmouseover" => "Tip('Test');"), null, false); 

可以指定与图像的链接和的onmouseover提供与该链路

0

HTML->图像( 'edit.png',[ 'URL'=> [ '动作'=>“编辑',$ playerEventRegistration-> id]],array(“onmouseover”=>“Tip('Test');”)?>