我创建了 2 个简单的函数,但函数 2 不起作用,我尝试将其更改为style.font-weight = "bold";但随后所有崩溃,该怎么办?
function validate() {
if (document.getElementById('remember').checked) {
document.getElementById("text").innerHTML = "HELLO WORLD!";
} else {
document.getElementById("text").innerHTML = "hello world!";
}
}
function validate2() {
if (document.getElementById('remember2').checked) {
document.getElementById("text").style = "bold";
} else {
document.getElementById("text").style = "normal";
}
}Run Code Online (Sandbox Code Playgroud)
<div id="text" style="font-weight: normal">hello world!</div>
<input id="remember" type="checkbox" onclick="validate()">Caps</input>
<br>
<input id="remember2" type="checkbox" onclick="validate2()">Bold</input>Run Code Online (Sandbox Code Playgroud)
这是镀铬问题还是什么?
我有随机.replace()的问题,它总是显示相同的随机数,我试图用不同的随机数替换$ random $.
$(document).ready(function() {
var arr = [
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10'
]
$("#present-users").children('li.present-user').each(function() {
arr.push($(this).find('img')[0].title);
});
var random = arr[Math.floor(Math.random() * arr.length)];
var text = "$random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$ $random$".replace(/\$random\$/g, random);
alert(text)
});
Run Code Online (Sandbox Code Playgroud)
谢谢,尼古拉