简体   繁体   English

将调色板添加到ASP.NET文本框

[英]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. 然后我会在所选文本之前添加类似HTML标记的前缀,之后当文本被反弹到div或任何其他HTML控件时,用户可以看到选择颜色的文本。

I hope to do so without using the AJAXControlToolkit. 我希望不使用AJAXControlToolkit这样做。

You can do this with jQuery if you don't mind using jQuery: 如果您不介意使用jQuery,可以使用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. colorpicker.js可以从这里下载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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