javascript - 使用 jquery 更改文本颜色和大小

标签 javascript jquery

我正在设置一个联系表单,其中包括简单的数学计算,我尝试更改文本的大小和颜色,即“$ + 总计”,但它不起作用。这是代码。

<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>

以及我想更改文本颜色和大小的部分。

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

最佳答案

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

关于javascript - 使用 jquery 更改文本颜色和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29153191/

相关文章:

javascript - 显示另一个文件中操作文件内的警报消息

Javascript 给出未定义的错误,尽管看起来一切正常

javascript - if 和 else 都不触发

javascript - 防止在文本区域中编辑单个单词

javascript - 如何求一个字符串中能被3整除的所有整数的总和?

javascript - 我是否正确使用了Underscore的throttle方法?

javascript - 使用过渡添加子项时 div 的平滑增长

javascript - 单击链接列表在右侧显示带有标题的内容

javascript - 如何仅在一种分辨率下隐藏-显示模态?

javascript - 如何解决我的http请求问题?