Jquery的新手,并试图从Prototype翻译一些代码

时间:2011-06-17 23:28:08

标签: javascript jquery

我正在尝试将这个代码从Prototype转换为Jquery中的相同内容:

$("follow_form").update("<%= escape_javascript(render('users/unfollow')) %>")
$("followers").update('<%= "#{@user.followers.count} followers" %>')

1 个答案:

答案 0 :(得分:6)

我想你想要:

$('#follow_form').html("<%= escape_javascript(render('users/unfollow')) %>");
$('#followers').html('<%= "#{@user.followers.count} followers" %>');

原型“$”函数是“document.getElementById()”的缩写(排序;它在IE上稍微复杂一点)。对于jQuery,您必须使用类似CSS的选择器语法。然后,Prototype中的“.update()”函数用于访问带有一些额外清理行为的“innerHTML”,而jQuery的“.html()”类似。

相关问题