[英]Change background color upon textbox value changed
I want to change the background color of my webpage when a color is selected from a ASPColorPicker and color code is in textbox. 当我从ASPColorPicker中选择一种颜色并且在文本框中输入颜色代码时,我想更改网页的背景颜色。 I have this jQuery code
我有这个jQuery代码
<script type="text/javascript">
function changeColor() {
$('#page').css('background', $("#colorPickerTextBox").val());
}
$("#colorPickerTextBox").change(changeColor);
</script>
And the TextBox 和文本框
<asp:TextBox ID="colorPickerTextBox" onchange="changeColor" runat="server">
</asp:TextBox>
<asp:ColorPickerExtender TargetControlID="colorPickerTextBox" ID="ColorPicker" runat="server">
</asp:ColorPickerExtender>
And in CSS I have this ID 在CSS中,我有这个ID
#page {
width: 990px;
margin: 0 auto;
padding: 20px 5px;
background: #FF99FF;
}
Add a JavaScript function: 添加一个JavaScript函数:
function selectedColorChanged(sender) {
$("#page").css({
backgroundColor: "#" + sender.get_selectedColor()
});
}
And an OnClientColorSelectionChanged
parameter with this function name to your ColorPickerExtender
: 并将具有此函数名称的
OnClientColorSelectionChanged
参数传递给您的ColorPickerExtender
:
<asp:ColorPickerExtender TargetControlID="colorPickerTextBox"
ID="ColorPicker"
runat="server"
OnClientColorSelectionChanged="selectedColorChanged">
</asp:ColorPickerExtender>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.