简体   繁体   English

如何使Yii框架的CGridView的linkHtmlOptions显示为图像图标,并在单击时触发javascript / jquery?

[英]how to make the linkHtmlOptions of Yii framework's CGridView appear as an image icon and when clicked, triggers a javascript/jquery?

here's the part where i need help in my CGridView of Yii framework web app 这是在Yii框架Web应用程序的CGridView中需要帮助的部分

  array(
       'class'=>'CLinkColumn',
       'linkHtmlOptions'=>array("onclick"=>"$('.fancybox').fancybox()"),
       'header'=>'Image',
  ),

currently, when i view that at the front-end, it shows "Link" as a hyperlink.. what i want to happen is, it will show a clickable image icon like eg /images/click_icon.jpg instead of an ordinary word hyperlink, then once it is clicked, it should call this 当前,当我在前端查看时,它显示“链接”为超链接..我想发生的是,它将显示可点击的图像图标,例如/images/click_icon.jpg,而不是普通的单词超链接,然后单击它,则应调用此

$(".fancybox").fancybox();

so how to do that in that array i pasted above ? 那么如何在我上面粘贴的数组中做到这一点呢?

You can use imageUrl property of CLinkColumn : 您可以使用imageUrl属性

array(
   'class'=>'CLinkColumn',
   'linkHtmlOptions'=>array("onclick"=>"$('.fancybox').fancybox()"),
   'header'=>'Image',
   'imageUrl'=>Yii::app()->baseUrl.'/images/click_icon.jpg'
),

Wherever you store the images, that url will have to be provided, for the above example, images are in the project root, hence i used Yii::app()->baseUrl . 无论在哪里存储图像,都必须提供该url,对于上面的示例,图像位于项目根目录中,因此我使用了Yii::app()->baseUrl

When you write 当你写

'linkHtmlOptions'=> array("onclick"=>"$('.fancybox').fancybox()"),

what you are actually doing is triggering the initialization of all the matched elements by the class selector '.fancybox', on the 'click' event. 您实际要做的是在“ click”事件上通过类选择器“ .fancybox”触发所有匹配元素的初始化。 Although you are doing the initialization, you are not leting fancybox manage the elements' onclick event in the proper way. 尽管正在执行初始化,但是并没有让fancybox以适当的方式管理元素的onclick事件。

You should have 你应该有

'linkHtmlOptions'=> array("onclick"=>"$('.fancybox').click()"),

and, as the instructions at the fancybox site show, put the fancybox initialization in the document.ready event. 然后,如fancybox网站上的说明所示,将fancybox初始化放入document.ready事件中。 But if you insist to initialize the fancybox object in the grid, you should write 但是,如果您坚持要初始化网格中的fancybox对象,则应编写

'linkHtmlOptions'=> array("onclick"=>"$('.fancybox').fancybox(); $('.fancybox').click()"),

But you may need to wait in between these two calls, would have to test it... 但是您可能需要在这两个调用之间等待,必须对其进行测试...

By the way, you are repeating the same link over and over again for every cell in the grid column. 顺便说一句,您要为网格列中的每个单元一遍又一遍地重复同一链接。 Does it make any sense? 有什么意义吗? I would put the link outside the grid. 我会将链接放在网格之外。

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

相关问题 如何使元素仅在javascript中单击按钮时显示 - How to make elements appear only when button is clicked in javascript Javscaript 使单击按钮时显示图像 - Javscaript Make image appear when button is clicked Javascript - 单击时显示带有图像的文本 - Javascript - have text appear with an image when clicked on 如何使Google Maps图标始终显示在地图中心-单击该图标? - How can I make Google Maps icon to always appear in the center of map - when clicked? 单击汉堡图标时如何使导航栏链接垂直显示在导航栏下方 - How to make navbar links appear vertically below the navbar when hamburger icon is clicked 如何使用Jquery / JavaScript使此图像滑块在单击时滑动一次以上? - How do I make this image slider to slide more than once when clicked, using Jquery/JavaScript? 当href处于另一个单击时会触发事件的类中时,如何使href发挥作用 - How to make an a href do its work when it's inside another class that triggers an event whenver clicked 我如何才能使div仅在jQuery中单击特定元素时显示? - How can I make a div appear only when a specific element gets clicked in jQuery? 单击某些复选框时,如何使来自 javascript 的字符串出现在 html 中? - How do I make a string from javascript appear in the html when certain checkboxes are clicked? Yii CGridView javascript事件的分页 - Yii CGridView javascript event on pagination
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM