关于Jscolor如何申请不同的ID

时间:2016-08-28 19:11:17

标签: javascript jquery css css3

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

1 个答案:

答案 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">