我正在嘗試使用JavaScript/JQuery
編輯css
值。我有一個variable
我創造,我想給它分配是這樣的:使用JavaScript/JQuery應用css值
var amount = 200;
$("p").css({"background-color": "yellow", "font-size": "amount%"}); // 200%
它僅適用的顏色,不是字體大小。我做錯了什麼,我該如何解決?
這裏有一個JSFiddle,這裏是代碼:
$(document).ready(function(){
$("button").click(function(){
var amount = 200;
$("p").css({"background-color": "yellow", "font-size": "amount%"});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<h2>This is a heading</h2>
<p style="background-color:#ff0000">This is a paragraph.</p>
<p style="background-color:#00ff00">This is a paragraph.</p>
<p style="background-color:#0000ff">This is a paragraph.</p>
<p>This is a paragraph.</p>
<button>Set background-color of p</button>
</body>
變化' 「量%」''到量+ 「%」' – Griffith