[英]how to get style=“i want the css code” using regexp (javascript)
[英]I want to change css style using javascript
我想根據用戶要求添加字體樣式並在textarea中鍵入。 我試過但是我的腳本不能正常工作......
function run() {
var fontType = document.getElementById("font_type").value;
var fontSize = document.getElementById("font_size").value;
var textArea = document.getElementById("msg");
//alert(fontType+fontSize);
textArea.style.font-size = fontSize ;
textArea.style.font-family = fontType;
}
請嘗試以下方法:
textArea.style.fontSize = fontSize ;
textArea.style.fontFamily = fontType;
否則,您的JavaScript將被評估為:
textArea.style.font - size = fontSize;
textArea.style.font - family = fontType;
...沒有任何意義(因此拋出一個ReferenceError: Invalid left-hand side in assignment
)。
當改變JavaScript中的所有樣式屬性( border-radius
- > borderRadius
等)時,這種轉換( something-something
與somethingSomething
something-something
somethingSomething
)是一致的。
嘗試:
textArea.style.fontSize = fontSize ;
textArea.style.fontFamily = fontType;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.