简体   繁体   English

MarkupBuilder-如何添加表td属性“ title”

[英]MarkupBuilder - how to add table td attribute “title”

I am looking to add table td "title" attribute along with td content. 我想添加表td“ title”属性以及td内容。 is there any way to do this 有没有办法做到这一点

You have to use Javascript/Jquery. 您必须使用Javascript / Jquery。 Try below code: 试试下面的代码:

$('td').on('mouseover', function(){
  var td = $(this);
  td.attr('title', td.html())
})

I used groovy markup builder in the context of grails tags libs, I share a small custom tag with the requirement that you mention. 我在grails标签库的上下文中使用了groovy标记构建器,我与您提到的需求共享一个小的自定义标签。 See how the title attribute is added to the td tag 查看title属性如何添加到td标签

import groovy.xml.*

def table = {
    MarkupBuilder mb = new MarkupBuilder(out)

    mb.table {
        thead {
            tr {
                th 'Col1'
                th 'Col2'
                th 'Col3'
            }
        }

        tbody {
            tr {
                td(title: 'lorem ipsum') {
                    mb.yield 'Text1'
                }

                td 'Text1'

                td 'Text1'
            }

            tr {
                td(title: 'lorem ipsum') {
                    mb.yield 'Text2'
                }

                td 'Text2'

                td 'Text2'
            }
        }
    }
}

In the view you can invoke the new tag in this way, assuming you use the namespace location 在视图中,假设您使用名称空间位置,则可以通过这种方式调用新标记

<location:table/>

This will draw the following table in the browser 这将在浏览器中绘制下表

在此处输入图片说明

It's certainly not pretty but it's made with markup builder and it has some td with the title attribute. 它当然不是很漂亮,但是它是由标记生成器制成的,并且带有一些带有title属性的td。

This link is an excellent resource to understand tags libs in grails and contains examples using markup builder 链接是理解grails中的标签库的绝佳资源,并且包含使用标记生成器的示例

For how to use markup builder in a context other than grails tag libs, visit this post of who else if not Mr Haki 有关如何在grails标记库以外的上下文中使用标记生成器的信息,请访问这篇文章

I hope it is useful for you 希望对您有用

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

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