简体   繁体   English

用jQuery更改文本颜色和大小

[英]Changing text color and size with jquery

I'm setting up a contact form that includes simple a math calculation, and I tried changing the size and color of the text which is the "$ + total" and it's just not working. 我正在建立一个包含简单数学计算的联系表,我试图更改文本的大小和颜色,即“ $ + total”,但它不起作用。 Here is the code. 这是代码。

 <div id="form-total"></div> <script> jQuery(document).ready(function ($) { var calculate = function () { var total = 0.00; // Check the chosen option of a select menu var val1 = $('.iphorm_1_1').val(); if (val1 == 'Ebook') { total += 150; } else if (val1 == 'Print Book') { total += 175; } else if (val1 == 'Magazine') { total += 200; } else if (val1 == 'Other') { total += 150; } // A second select menu var val2 = $('.iphorm_1_2').val(); if (val2 == 'Non-Fiction') { total += 0; } else if (val2 == 'Fiction') { total += 0; } else if (val2 == 'Other') { total += 0; } var val3 = $('.iphorm_1_3').val(); if (val3 == '2') { total += 0; } else if (val3 == '3') { total += 50; } else if (val3 == '4') { total += 100; } else if (val3 == '5') { total += 150; } else if (val3 == '6') { total += 200; } else if (val3 == '7') { total += 250; } else if (val3 == '8') { total += 300; } else if (val3 == '9') { total += 350; } else if (val3 == '10') { total += 400; } // Display the result to the user $('#form-total').text('$' + total); // Set the value of the hidden field $('input[name=iphorm_1_7]').val('$' + total); }; // Calculate on page load calculate(); // Recalculate when these select menus are changed $('.iphorm_1_1, .iphorm_1_2, .iphorm_1_3').change(calculate); }); </script> 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

And the part where i want to change the text color and size. 而我要更改文本颜色和大小的部分。

 $('#form-total').text('$' + total); 

You can change size and color with jQuery .css property. 您可以使用jQuery .css属性更改大小和颜色。 Like so: 像这样:

element.css('font-size','15px');

and

element.css('color','#000000');

So you can add that to your text code or put that text code in a variable and then add the css above to the variable. 因此,您可以将其添加到文本代码中,或将该文本代码放入变量中,然后将上面的css添加到变量中。

$('#form-total').text('$' + total).css({"color": "green", "font-size": "400px"});

$('#form-total')。text('$'+ total).css({font-size:'YOUR_SIZE',color:'YOUR_COLOR'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM