如何在VAADIN 6客户端的自定义小部件中编写javascript代码

时间:2014-09-04 07:23:56

标签: javascript jquery html vaadin

我正在尝试创建一个简单的小部件,其中包含一个简单的div和jquery。因为我必须在该小部件的客户端编写javascript代码。我试着用HTML编写javascript但它不起作用。这是我的代码。

 public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    // This call should be made first. 
    // It handles sizes, captions, tooltips, etc. automatically.
    if (client.updateComponent(this, uidl, true)) {
        // If client.updateComponent returns true there has been no changes and we
        // do not need to update anything.
        return;
    }

    // Save reference to server connection object to be able to send
    // user interaction later
    this.client = client;

    // Save the client side identifier (paintable id) for the widget
    paintableId = uidl.getId();

    // Process attributes/variables from the server
    // The attribute names are the same as we used in 
    // paintContent on the server-side
    int clicks = uidl.getIntAttribute("clicks");
    String message = uidl.getStringAttribute("message");
    String myScript = "<script language='javascript' type='text/javascript'>$(document).ready(function(){$('#mytest').click(function(){alert('Clicked')})})</script>";

    getElement().setInnerHTML(myScript+"<div id='mytest'>Click me</div>");
    //getElement().setInnerHTML("After <b>"+clicks+"</b> mouse clicks:\n" + message);

}
浏览器中的

检查元素HTML是这样的 enter image description here

但此警报未显示。怎么做。请帮忙。我厌倦了谷歌这个问题。 我正在使用Vaadin 6

谢谢

0 个答案:

没有答案