JQuery与原型代码的等价

时间:2011-10-25 22:00:28

标签: jquery prototypejs

与此Prototype代码相当的jQuery是什么?

如果您认为这不相关并且关闭它,您是否介意直接向我发送解决方案?

var comment_link = new Element('a', {
    'title': "View snapshot", 
    'id': snapshot.id + '_comment', 
    'href': "#", 
    'class': ""
}).update(snapshot.name.truncate(13));

comment_link.observe('click', respondToClick);
comment_link.observe('mouseover', respondToMouseOver);
comment_link.observe('mouseout', respondToMouseOut);

我试过这个无济于事:

var comment_link = new $j('<a/>', {
    title: "View snapshot", 
    id: snapshot.id + '_comment', 
    href: "#", 
    class: ""
}).html(snapshot.name.truncate(13));

$j(comment_link).click(respondToClick);
$j(comment_link).mouseover(respondToMouseOver);
$j(comment_link).mouseout(respondToMouseOut);

1 个答案:

答案 0 :(得分:0)

var comment_link = $j('<a/>')
  .attr('title', 'View snapshot')
  .attr('id', snapshot.id + '_comment')
  .attr('href', '#')
  .html(snapshot.name.truncate(13))
  .click(respondToClick)
  .mouseover(respondToMouseOver)
  .mouseout(respondToMouseOut);

应该这样做