在jQuery中更新类似Facebook的URL

在jQuery中更新类似Facebook的URL,jquery,facebook,Jquery,Facebook,我有以下脚本。正如您所见,它确实更新了fb href,但由于某些奇怪的原因,like无法处理。我弄糟什么了吗 <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> </head> <script> $(document).read

我有以下脚本。正如您所见,它确实更新了fb href,但由于某些奇怪的原因,like无法处理。我弄糟什么了吗

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> 
</head>
<script>
$(document).ready(function() {
    $('#submit').click(function() {
        $('fb\\:like').attr('href', $("#URL").val());
    });
});
</script>
<body>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=174802005910704&amp;xfbml=1"></script>
<fb:like href="#" send="false" layout="box_count" width="80" show_faces="false" font=""></fb:like>
<input type="text" id="URL" />
<input type="button" id="submit" value="go">
</body>
</html>

任何帮助都将不胜感激。

不,这不会有多大作用,因为标记已经被处理和呈现。如果它真的起作用,你所要做的就是改变属性,这没有任何效果

试着解释一下你想要完成什么,你会得到一个更好的答案

将此添加到你的html中

<div class="share"></div>
加载时,当按下按钮或某些状态发生变化时,调用此功能

function update_share_location() {

    // Empty previous share stuff
    $('.share').empty();

    // Your new share location
    var url_loc = 'http://yournewshare.com';

    share_options = '<iframe src="//www.facebook.com/plugins/like.php?href='+url_loc+'&amp;send=false&amp;layout=button_count&amp;width=250&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=26" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:26px;" allowTransparency="true"></iframe>';

    // Update html
    $('.share').html(share_options);


}

谢谢你的回复。我正在尝试从表单中更新类似Facebook的URL。。您正在成功地更新它,但这不会改变页面上的任何内容,请尝试使用firebug查看您的DOM,这样您就会更好地理解我的答案,like按钮已在iframe中打开,不再依赖like标记。在呈现之前如何更改属性?您可以在html中更改它,或者使用正确的url属性动态插入它。我知道您正在尝试做什么。。您正试图通过在一个页面上单击“喜欢”来让用户喜欢另一个页面。不行,兄弟,fb:like按钮是在iframe中呈现的,您不能在呈现后更改其href programmaticaly。不过这是一个不错的尝试: