<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">
答案 0 :(得分:0)
仅使用一个更新功能,并在该功能中添加要更改的任何元素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">