2014-08-28 37 views
0

我正在创建一个字体示例,它将在选项选择上进行更改。然而,它似乎没有工作。我对以前的问题使用过类似的格式,但不知何故,这次似乎没有回应。谢谢!使用jQuery开关更改输入更改图像

<div class="form-input"> 
<label class="label" for="font-choice">Not sure which font? Choose from our top 12: </label> 
<select class="form-select" id="engraving-type"> 
<option style="font-family: Arial" value="Arial">&nbsp; &nbsp; &nbsp; Arial</option> 
<option style="font-family: Baskerville" value="Baskerville"> &nbsp; &nbsp; &nbsp; Baskerville</option> 
<option style="font-family: Baroness Bold" value="Baroness Bold"> &nbsp; &nbsp; &nbsp; Baroness Bold</option> 
<option style="font-family: Cantania" value="Cantania"> &nbsp; &nbsp; &nbsp; Cantania</option> 
<option style="font-family: Century Gothic" value="Century Gothic"> &nbsp; &nbsp; &nbsp; Century Gothic</option> 
<option style="font-family: Chinese" value="Chinese"> &nbsp; &nbsp; &nbsp; Chinese</option> 
<option style="font-family: Edwardian Script" value="Edwardian Script"> &nbsp; &nbsp; &nbsp; Edwardian Script</option> 
<option style="font-family: Dagobent" value="Dagobent"> &nbsp; &nbsp; &nbsp; Dagobent</option> 
<option style="font-family: Goudy" value="Goudy"> &nbsp; &nbsp; &nbsp; Goudy</option> 
<option style="font-family: Palatino" value="Palatino"> &nbsp; &nbsp; &nbsp; Palatino</option> 
<option style="font-family: Baroness Bold" value="Baroness Bold"> &nbsp; &nbsp; &nbsp; Baroness Bold</option> 
<option style="font-family: Times New Roman" value="Times New Roman"> &nbsp; &nbsp; &nbsp; Times New Roman</option> 
</select> 
</div> 


<div class="form-input"> 
<label class="label" for="form-table">Font example:</label><span id="text-example"><img id="font-image" src="/images/fonts/Font-Baskerville.jpg" /></span> 
</div> 
<script> 
    $(document).ready(function() { 
    $("#engraving-type").change(function(){ 
    switch (this.value) { 
    case 'Arial': 
     var image = 'Font-Arial.jpg'; 
     break; 
    case 'Baskerville': 
     var image = '/#'; 
     break; 
    default: 
     var image = 'Font-Baskerville.jpg'; 
     break; 
    } 
    $("#font-image").attr("src", "/images/fonts/" + image); 
    }); 
}); 
</script> 
+0

如果警报(图),您得到了什么?请尝试告诉我 – 2014-08-28 11:18:00

+0

它适合我 - http://jsfiddle.net/u3pjujab/ – 2014-08-28 11:21:43

+0

请让你添加jquery库吗? – 2014-08-28 11:22:19

回答

-1

替换该行

switch (this.value) 

switch ($(this).val()) 
+0

为什么downvote ...? – Shail 2014-08-28 11:11:20

+0

这两种情况都是正确的。一个是纯javascript和另一个jquery – 2014-08-28 11:11:47

+1

这不是解决方案。谢谢 – 2014-08-28 11:14:26