1

我是 Web 开发的新手,我有一个关于光谱颜色选择器的问题,我在我的项目中使用光谱颜色选择器,当我将它用于背景时它工作得很好,但是当我用于文本时它不能正常工作,当我从光谱颜色选择器中选择一种颜色,文本颜色发生变化,但初始颜色没有更新,它与我在脚本中初始化的颜色相同。我的脚本有什么问题。请帮助我解决我的问题。这是以下代码。

<label>TextColor</label>

<input type='color' id="full"/>

<script type="text/javascript">
$(document).ready(function(){
$("#full").spectrum({
    showInput: true,
    className: "full-spectrum",
    showInitial: true,
    showPalette: true,
    showSelectionPalette: true,
    localStorageKey: "full",
    maxPaletteSize: 10,
    preferredFormat: "hex",
    move: function (full) {

    },
    show: function (full) {

    },
    beforeShow: function (full) {

    },
    hide: function (full) {

    },
    change: function(full) {
    $("#full").on('change',function(){ format('foreColor' ,$("#full").val());  });

    },
    palette: [
        ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)",
        "rgb(204, 204, 204)", "rgb(217, 217, 217)","rgb(255, 255, 255)"],
        ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
        "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"],
        ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
        "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
        "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
        "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
        "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
        "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
        "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
        "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
        "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
        "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
    ]
});
});
</script>

我的 html 代码如下,其中文本颜色(仅限单个 div 中的选定文本)必须使用选定的颜色进行更新:

<div id="canvas-wrap"><!-- This div is the canvas wrap -->
<canvas id="mycanvas" width="400px" height="250px" style="border:1px solid #d3d3d3; ">
</canvas>
<!-- This is the Script of Image Uploader --> 
<script type="text/javascript">
var imageLoader = document.getElementById('imageLoader');
    imageLoader.addEventListener('change', handleImage, false);
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
mycanvas.style.border = "red 1px solid";


var x = 0;
var y = 0;
var width = 400;
var height = 250;

function handleImage(e){
    var reader = new FileReader();
    reader.onload = function(event){
        var img = new Image();
        img.onload = function(){

            ctx.drawImage(img, x, y, width, height);
        }
        img.src = event.target.result;
    }
    reader.readAsDataURL(e.target.files[0]);    
}
</script>


   <div class="resizeDiv" id="yname" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Your Name</span></div>

   <div class="resizeDiv" id="designation" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Designation</span></div>

   <div class="resizeDiv" id="cname" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Your Company Name</span></div>

   <div class="resizeDiv" id="youraddress1" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Your address1</span></div>

   <div class="resizeDiv" id="youraddress2" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Your address2</span></div>

   <div class="resizeDiv" id="email" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Email</span></div>

   <div class="resizeDiv" id="website" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);" style=""><span>Website</span> </div>

   <div class="resizeDiv" id="phoneno" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>+91 1234567890</span></div>

   <div class="resizeDiv" id="faxno" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>+(91) 80 400 10 200</span></div>

   <div class="resizeDiv" id="mno" ondblclick="contentEditable='true'" onfocus="document.execCommand('selectAll',false,null);"><span>Mobile no.</span></div>

 </div>
4

0 回答 0