我需要从JS更改div(仪表板)的背景颜色。到目前为止,它仅更改一秒钟,然后重置为原始颜色。
function validateForm() {
var divtag = document.getElementById("dashboard");
divtag.style.backgroundColor = "red";
}
<div id="dashboard">
<i class="fas fa-compact-disc fa-5x"></i>
<form>
<fieldset>
<legend>Track Search</legend>
<input type="text" id="tname" name="tname" placeholder="Specify a Track">
<button class="far fa-file-audio fa-2x" onclick="searchT()"></button>
</fieldset>
</form>
<form name="color" onsubmit="validateForm()">
<fieldset>
<legend>Music Dashboard Scheme</legend>
<input type="radio" id="RGB" name="choice" value="RGB" checked="checked">
<label for="RGB">RGB</label>
<input type="radio" id="HEX" name="choice" value="HEX">
<label for="HEX">HEX</label>
<input type="text" id="cvalue" name="cvalue" placeholder="Enter Colour Value" required>
<input type="submit" src="fas fa-palette fa-2x" alt="Submit"></input>
</fieldset>
</form>
</div>
您需要使用preventDefault
来禁用默认的提交行为。
像那样:
function validateForm(event) {
event.preventDefault();
var divtag = document.getElementById("dashboard");
divtag.style.backgroundColor = "red";
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句