gpt4 book ai didi

javascript - 关于Jscolor如何申请不同的ID

转载 作者:行者123 更新时间:2023-11-28 05:18:23 26 4
gpt4 key购买 nike

<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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com