简体   繁体   中英

Add Color Palette to ASP.NET Textbox

I need to add a color palette to my form so the user could select specific text inside a normal text box then choose a color from the palette.

Then I would add a prefix like HTML tag before the selected text and after so when the text is rebound into a div or any other HTML controls the user could see the text in choosen color.

I hope to do so without using the AJAXControlToolkit.

You can do this with jQuery if you don't mind using jQuery:

Having an regular text input element like so:

<input type="text" maxlength="6" size="6" id="colorpickerField1" value="00ff00">

You can create a Color picker doing:

<script type="text/javascript" src="js/colorpicker.js"></script>

$(document).ready(function(){
   $('#colorpickerField1').ColorPicker({
    onSubmit: function(hsb, hex, rgb, el) {
        $(el).val(hex);
        $(el).ColorPickerHide();
    },
    onBeforeShow: function () {
        $(this).ColorPickerSetColor(this.value);
    }
   })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
      });
});

And colorpicker.js can be downloaded from here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM