求JS代码:点击弹出div,选择图片后,使另一个div显示对应的字体类型
<divid="font_select"><divid="font"class="font_select_box"><ahref="javascript:void(0)"...
<div id="font_select" >
<div id="font" class="font_select_box">
<a href="javascript:void(0)">Change Font</a></div>
<script type="text/javascript">
$(document).ready(function(){
$("#font").click(function(e){
$("#tooltips0").toggle();
e.stopPropagation();
});
$(document).click(function() {
$("#tooltips0").hide();
});
$(".font_selectGroups li").click(function(){
var thistext = $(this).text();
$("#tooltips0").hide();
$("#attrib_5_0").val(thistext);
});
});
</script>
<div id="tooltips0" style="display:none;">
<ul class="font_selectGroups" style="text-align:left">
<li><a href="javascript:void(0)"><img src="images/font/Aarvarkcafe.png"></br>Aarvark cafe</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Adobegaramondbold.png"></br>Adobe garamond bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Airstream.png"></br>Air stream</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Aldosemibold.png"></br>Aldo semi bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Andybold.png"></br>Andy bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Arialblack.png"></br>Arial black</a></li>
</ul></div> </div>
<div id="fontshow"> </div> //需要显示字体类型的div 展开
<div id="font" class="font_select_box">
<a href="javascript:void(0)">Change Font</a></div>
<script type="text/javascript">
$(document).ready(function(){
$("#font").click(function(e){
$("#tooltips0").toggle();
e.stopPropagation();
});
$(document).click(function() {
$("#tooltips0").hide();
});
$(".font_selectGroups li").click(function(){
var thistext = $(this).text();
$("#tooltips0").hide();
$("#attrib_5_0").val(thistext);
});
});
</script>
<div id="tooltips0" style="display:none;">
<ul class="font_selectGroups" style="text-align:left">
<li><a href="javascript:void(0)"><img src="images/font/Aarvarkcafe.png"></br>Aarvark cafe</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Adobegaramondbold.png"></br>Adobe garamond bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Airstream.png"></br>Air stream</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Aldosemibold.png"></br>Aldo semi bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Andybold.png"></br>Andy bold</a></li>
<li><a href="javascript:void(0)"><img src="images/font/Arialblack.png"></br>Arial black</a></li>
</ul></div> </div>
<div id="fontshow"> </div> //需要显示字体类型的div 展开
2个回答
展开全部
<script type="text/javascript">
$(document).ready(function(){
$("#font").click(function(e){
$("#tooltips0").toggle();
e.stopPropagation();
});
$(document).click(function() {
$("#tooltips0").hide();
});
// 改这里就可以了哟
$(".font_selectGroups li").click(function(){
$("#tooltips0").hide();
$("#fontshow").text(/\/(\w+)\.png$/.exec($(this).find('img').attr('src'))[1]);
});
});
</script>
追问
不好意思,可能我说得不够清楚,
我的意思是要在#fontshow中显示字体的样式,不是字体的名字,
比如我选择了“Arial black” 这种字体,就在#fontshow中显示这种字体样式,
字体文件我已经有了的,差就JS代码不会,
应该是用CSS的@font-face吧,
然后选择了字体类型后改变#fontshow的font-family,
这样能做得到吗?
谢谢!
追答
$(document).ready(function(){
$("#font").click(function(e){
$("#tooltips0").toggle();
e.stopPropagation();
});
$(document).click(function() {
$("#tooltips0").hide();
});
// 改这里就可以了哟
$(".font_selectGroups li").click(function(){
var selectedFamily = /\/(\w+)\.png$/.exec($(this).find('img').attr('src'))[1];
//在这个映射表里填写图片名称对应的字体名称就可以了哟
var FamilyMap = {
Aarvarkcafe:'',
Adobegaramondbold:'',
Airstream:'',
Aldosemibold:'',
Andybold: '',
Arialblack:'Arial black',
};
$("#tooltips0").hide();
$("#fontshow").text(selectedFamily).css('font-family',FamilyMap[selectedFamily]);
});
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询