2011-04-18 114 views
0

我希望能够将某个文本从一个div复制到另一个div。将某个文本从一个div复制到另一个div

该文本是从一个Wordpress插件生成的,它生成2个不同的div,其中1个被调用.voting不活动,另一个被称为.voting。

生成的文本是基于评分的,它看起来是这样的:评分4.5/5,我只想采取4.5或任何投票生成,并将其复制到一个div来很好地显示结果。

任何帮助将是伟大的。

+0

您好保罗,头脑改变你的显示名称,而它的WordPress插件的问题? – 2011-04-18 11:55:20

回答

0

一个例子

HTML

<div id="this">Sometext</div> 
<div id="that"></div> 

脚本

$(document).ready(function() { 
    $("#that").html($("#this").html()); 
}); 
0

试试这个:

var vote = $(".voting").text().split("/")[0]; 
2

我@Starx我就这一个。但是,仅仅是多一点明确:

<div> 
    Rating 
    <span id="average">4.5</span>/ 
    <span id="highest_possible">5</span> 
</div> 

<div id="target"> 
    <!-- This could be any element --> 
</div> 

然后JS

$(document).ready(function() { 
    $("#target").html($("#average").html()); 
}); 

希望帮助!

1

设法得到它working-感谢所有的答案:-)

<html> 
<head> 

<style type="text/css"> 
#target-rating{font-size:30px; text-align:center; font-weight:bold;} 
</style> 

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script> 

<script type="text/javascript"> 
/*$(document).ready(function() { 
     //var arrayOne = $('.voted').html().split('/'); 
     var arrayOne = $('div[class*="voted"]').html().split('/'); 
     var arrayTwo = arrayOne[0].split(' '); // arrayTwo[1] contains ie: 4.4 
     $('#target-rating').html(arrayTwo[1]); 
});*/ 
</script> 

<script type="text/javascript"> 
// This works for 2 divs 
$(function() { 
     var rating = $('div.inactive,div.voted inactive').text().replace(/^.*: ([\d\.]+).*$/, '$1'); // Extract the rating 
     $('#target-rating').text(rating); // And copy 
}); 
</script> 

</head> 
<body> 
<div id="target-rating"></div> 

<!-- Example divs --> 
<div class="inactive" id="gdsr_mur_text_796_1">Rating: 4.4/<strong>5</strong> (5 votes cast)</div> 
<div class="voted inactive" id="gdsr_mur_text_796_1">Rating: 5.0/<strong>5</strong> (5 votes cast)</div> 

</body> 
</html> 
0
<a class="hello">Copy It</a> 
<a class="goodbye"></a> 


(function($) { 
    $('.hello').click(function() { 

     $(this).clone().appendTo(".goodbye"); 
    }); 
})(jQuery); 
相关问题