【发布时间】:2012-03-02 20:13:10
【问题描述】:
我使用JSColor 作为我网站的颜色选择器,由于更新面板,我在回发后丢失其实例的问题很少,但在其他问题中找到了解决方案:
private void RegisterClientStartupScript(string scriptKey, string scriptText)
{
ScriptManager sManager = ScriptManager.GetCurrent(this.Page);
if (sManager != null && sManager.IsInAsyncPostBack)
{
//if a MS AJAX request, use the Scriptmanager class
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), scriptKey, scriptText, true);
}
else
{
//if a standard postback, use the standard ClientScript method
scriptText = string.Concat("Sys.Application.add_load(function(){", scriptText, "});");
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), scriptKey, scriptText, true);
}
并像这样在 page_load 中使用它解决了问题:
RegisterClientStartupScript("some", "jscolor.init();");
现在我让它在 Firefox 中完美运行,但在 Chrome 中,当我按下按钮时它甚至无法打开,这是它在标记中的设置方式:
<script type="text/javascript" src="jscolor/jscolor.js"></script>
在正文中:
<asp:TextBox ID="txtButtonTextColorSample" runat="server" Width="30px"></asp:TextBox>
<asp:TextBox ID="txtButtonTextColor" runat="server" OnTextChanged="txtButtonTextColor_TextChanged"></asp:TextBox>
<input type="button" id="fontCPicker" value="Pick" class="color {valueElement:'txtButtonTextColor',styleElement:'txtButtonTextColorSample',hash:true,required:false}" />
<input type="button" onclick=" doPostBackAsync('<%= txtButtonTextColor.ClientID %>', 'OnTextChanged');" value="Apply" />
它应该在按钮“fontCPicker”时显示,但什么也没发生,我在 Chrome 控制台中没有看到任何错误,但我不确定它是否真的在调试,因为我不经常使用 Chrome。
【问题讨论】:
-
click的fontCPicker事件监听器在哪里? -
@Nick 看看 JSColor 的链接,它应该通过在要绑定到对话框的元素上指定 class="color" 来工作,导入的 js 文件完成其余的工作,就像我一样说它在 Firefox 中运行良好
-
在此页面上尝试示例 #7,让我知道它是否适用于 Chrome:jscolor.com/try.php
-
@Nick 我不知道如何,但它在 chrome 中工作,我的示例做错了什么?
-
{valueElement:'txtButtonTextColor',styleElement:'txtButtonTextColorSample',hash:true,required:false}返回什么?
标签: c# javascript asp.net google-chrome jscolor