Jquery 加载外部js文件,用于使用.load在刷新的div中不工作的社交按钮
我有一个包含新闻容器、社交按钮容器和评论框容器的框。该框具有固定高度,因此我无法使用。我希望刷新该框。问题是,当我在框中使用.load时,社交按钮不起作用,因为它使用的是外部的.js文件。这可能吗 这是我的盒子:Jquery 加载外部js文件,用于使用.load在刷新的div中不工作的社交按钮,jquery,html,Jquery,Html,我有一个包含新闻容器、社交按钮容器和评论框容器的框。该框具有固定高度,因此我无法使用。我希望刷新该框。问题是,当我在框中使用.load时,社交按钮不起作用,因为它使用的是外部的.js文件。这可能吗 这是我的盒子: <div class="pin-box" id="pinbox_<?php echo $row['articles_id'];?>"> <div class="box1"> <?php //Scr
<div class="pin-box" id="pinbox_<?php echo $row['articles_id'];?>">
<div class="box1">
<?php
//Script that will echo articles
?>
<hr class="art_line">
<div class="social_button" id="social_<?php echo $row['articles_id'];?>">
<span class='st_facebook_large' st_url='<?php echo base_url(); ?>index.php/be_informed/show/<?php echo $row['articles_id']; ?>' displayText='Facebook'></span>
<span class='st_twitter_large' st_url='<?php echo base_url(); ?>index.php/be_informed/show/<?php echo $row['articles_id']; ?>' displayText='Tweet'></span>
<span class='st_linkedin_large' st_url='<?php echo base_url(); ?>index.php/be_informed/show/<?php echo $row['articles_id']; ?>' displayText='LinkedIn'></span>
<span class='st_googleplus_large' st_url='<?php echo base_url(); ?>index.php/be_informed/show/<?php echo $row['articles_id']; ?>' displayText='Google +'></span>
</div>
<div id="space"></div>
<div id="beinformed_comment">
<?php
//Script that will echo comments
?>
</div>
</div>
</div>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">
stLight.options({publisher: "751d0899-1764-4d1f-aac0-1bf112ad5cfd",
doNotHash: false,
doNotCopy: false,
hashAddressBar: false
});
</script>
stLight.options({发布者:“751d0899-1764-4d1f-aac0-1bf112ad5cfd”,
多诺塔什:错,
不要抄袭:错,
hashAddressBar:false
});
以下是我的Jquery代码(我使用的是1.4.2):
$('.comment\u button\u article').live(“单击”,函数())
{
var ID=$(this.attr(“ID”);
var comment=$(“#ctextarea”+ID).val();
var user_id=$(“#user_id_”+id).val();
var dataString='comment='+comment+'&msg_id='+id+'&user_id='+user_id;
如果(注释=“”|注释==‘在此处输入您的注释’)
{
警告(“请输入注释”);
}
其他的
{
$.ajax({
类型:“POST”,
url:“comment_ajax.php”,
数据:dataString,
cache:false,
成功:函数(html){
$('index.php/be_informated/index#pinbox_uu'+ID).load('index.php/be#u informated/index#pinbox_u'+ID);
}
});
}
返回false;
});
我猜可能是外部脚本没有执行
在将内容添加到页面后(作为load()调用中的回调函数),您应该尝试手动调用脚本,如:
$.ajax({
type: "POST",
url: "comment_ajax.php",
data: dataString,
cache: false,
success: function(html){
$('#pinbox_'+ID).load('<?php echo base_url(); ?>index.php/be_informed/index #pinbox_'+ID, function(){
$.ajax({
dataType: "script",
cache: true,
url: 'http://w.sharethis.com/button/buttons.js'
});
});
}
});
$.ajax({
类型:“POST”,
url:“comment_ajax.php”,
数据:dataString,
cache:false,
成功:函数(html){
$('#pinbox_'+ID).load('index.php/be#u informated/index#pinbox_'+ID,function()){
$.ajax({
数据类型:“脚本”,
是的,
网址:'http://w.sharethis.com/button/buttons.js'
});
});
}
});
}代码不起作用。我想您所说的是jquery的getscript,但我读过它,jquery 1.4.2不支持它。
$.ajax({
type: "POST",
url: "comment_ajax.php",
data: dataString,
cache: false,
success: function(html){
$('#pinbox_'+ID).load('<?php echo base_url(); ?>index.php/be_informed/index #pinbox_'+ID, function(){
$.ajax({
dataType: "script",
cache: true,
url: 'http://w.sharethis.com/button/buttons.js'
});
});
}
});