【问题标题】:Can't get color of button in jQuery using jsColor无法使用 jsColor 在 jQuery 中获取按钮的颜色
【发布时间】:2016-09-27 19:36:13
【问题描述】:

我有一个按钮,它的作用类似于颜色选择器的触发器,它应该改变画布中文本的颜色。我使用的库是jscolor

<button class="color-picker-btn jscolor {valueElement:'valueElement', onFineChange:'update(this)', value:'ffffff'}"></button>
<input id="valueElement"></input>

js:

function update(jscolor) {
        console.log(jscolor);
        canvas.getActiveObject().fill = ( jscolor );
}

在控制台我得到这样的东西:

jscolor {value: "ffffff", valueElement: input#valueElement, styleElement: button.color-picker-btn.jscolor.{valueElement:'valueElement',.onFineChange:'update(this)',.value:'ff…, required: true, refine: true…}
_processParentElementsInDOM:()activeClass:"jscolor-active"
backgroundColor
:
"#FFFFFF"
borderColor
:
"#BBBBBB"
borderRadius
:
8
borderWidth
:
1
buttonColor
:
"#000000"
buttonHeight
:
18
closable
:
false

..还有更多的行。如何只获取颜色?

【问题讨论】:

    标签: javascript jquery jscolor


    【解决方案1】:

    你的问题是这里的这个,这是按钮:

    <button class="color-picker-btn jscolor {valueElement:'valueElement', onFineChange:'update(this)', value:'ffffff'}"></button>
    <input id="valueElement"></input>
    

    你可以像这样发送输入对象:

    <button class="color-picker-btn jscolor {valueElement:'valueElement', onFineChange:'update(valueElement)', value:'ffffff'}"></button>
    <input id="valueElement"></input>
    

    在您的 Javascript 函数中,从对象“值”中获取颜色:

    function update(jscolor) {
        console.log(jscolor.value);
        canvas.getActiveObject().fill = ( jscolor.value );
    }
    

    这是 jsfiddle 中的代码: https://jsfiddle.net/sidanmor/g8odgju6/

    【讨论】:

    • 很好的解决方案!
    猜你喜欢
    • 2012-06-10
    • 2022-01-02
    • 2012-02-10
    • 2012-08-28
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多