<script>
function update(jscolor) {
// 'jscolor' instance can be used as a string
document.getElementById('header').style.backgroundColor = '#' + jscolor
}
function update(jscolor) {
// 'jscolor' instance can be used as a string
document.getElementById('text').style.color = '#' + jscolor
}
</script>
<nav class="navbar navbar-default navbar-fixed-top" id="header">
<a class="navbar-brand" href="#" id="text">
Customize Your Website
</a>
<input name="color2" class="jscolor form-control" onchange="update(this.jscolor)" value="#FFF">
最佳答案
只使用一个更新函数并在该函数中添加您想要更改的元素的任何 id:
<script>
function update(jscolor) {
// 'jscolor' instance can be used as a string
document.getElementById('header').style.backgroundColor = '#' + jscolor
document.getElementById('text').style.color = '#' + jscolor
}
</script>
<nav class="navbar navbar-default navbar-fixed-top" id="header">
<a class="navbar-brand" href="#" id="text">
Customize Your Website
</a>
<input name="color2" class="jscolor form-control" onchange="update(this.jscolor)" value="#FFF">
关于javascript - 关于Jscolor如何申请不同的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39194859/