English 中文(简体)
在联合材料公司,我如何获得肤色的 he子?
原标题:In JSColor, how do I get the hex of the color?

在用户选取一个颜色后,我如何获得“hex”?

$("input#colorpicker").css( background-color ) => this returns background-color: rgb(107, 132, 255);

但并非一 he。

问题回答

I assume that jQuery.css returns the value that was set. Try the following function to convert RGB to HEX:

function colorToHex(color) {
    if (color.substr(0, 1) ===  # ) {
        return color;
    }
    var digits = /(.*?)rgb((d+), (d+), (d+))/.exec(color);

    var red = parseInt(digits[2]);
    var green = parseInt(digits[3]);
    var blue = parseInt(digits[4]);

    var rgb = blue | (green << 8) | (red << 16);
    return digits[1] +  #  + rgb.toString(16);
};

colorToHex( rgb(120, 120, 240) )

实际上,这在一定程度上取决于浏览器在rg或 he子中返回,任何东西都阻止了这种read子,对此也进行了清醒的讨论,也有许多解决办法。

Background-color hex to Javaform

以及

如何获得超重的彩色价值而不是液化物的价值?

以及

能够用六dec形式强行遣返Query.cs(“后院”)?

以及

jquery css color value returns RGB?

现有交流活动:

$("input#colorpicker").change(function() {
    console.log(this.color);
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签