我正在尝试使按钮的文本在单击时变为粗体。我尝试过使用这个问题的建议:How to make a text in font/weight style bold in JavaScript
function boldButton(){
$('#btn').style.fontWeight = '700';
}
答案 0 :(得分:2)
答案 1 :(得分:1)
//Inline
<button class="btn" id="btn1" onclick="this.style.fontWeight = 'bold'">Test1</button>
//OR with function
<button class="btn" id="btn2" onclick="boldButton(this)">Test2</button>
<scrypt>
function boldButton(btn){
btn.style.fontWeight = '700';
}
</scrypt>
答案 2 :(得分:0)
在通过javascript设置属性之前,您需要将jquery对象转换为javascript对象。还要确保定义了onclick方法:
function boldButton(num){
$('#btn'+num)[0].style.fontWeight = '700';
}
<强> Working Demo 强>