gpt4 book ai didi

c# - 在文本框值更改时更改背景颜色

转载 作者:行者123 更新时间:2023-11-28 11:14:06 25 4
gpt4 key购买 nike

当从 ASPColorPicker 中选择颜色并且颜色代码在文本框中时,我想更改我的网页的背景颜色。我有这个 jQuery 代码

<script type="text/javascript">
function changeColor() {
$('#page').css('background', $("#colorPickerTextBox").val());
}

$("#colorPickerTextBox").change(changeColor);
</script>

还有 TextBox

<asp:TextBox ID="colorPickerTextBox" onchange="changeColor" runat="server">
</asp:TextBox>
<asp:ColorPickerExtender TargetControlID="colorPickerTextBox" ID="ColorPicker" runat="server">
</asp:ColorPickerExtender>

CSS 中我有这个 ID

#page {
width: 990px;
margin: 0 auto;
padding: 20px 5px;
background: #FF99FF;
}

最佳答案

参见 this link .

添加 JavaScript 函数:

function selectedColorChanged(sender) {  
$("#page").css({
backgroundColor: "#" + sender.get_selectedColor()
});
}

还有一个带有此函数名称的 OnClientColorSelectionChanged 参数到您的 ColorPickerExtender:

<asp:ColorPickerExtender TargetControlID="colorPickerTextBox"
ID="ColorPicker"
runat="server"
OnClientColorSelectionChanged="selectedColorChanged">
</asp:ColorPickerExtender>

关于c# - 在文本框值更改时更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21838821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com