【问题标题】:What is the exact length of $("#dialog").html(message)$("#dialog").html(message) 的确切长度是多少
【发布时间】:2014-10-15 20:13:56
【问题描述】:

我正在使用Jquery Dialog,消息长度太大。我正在使用以下代码

JavaScript

function ShowPopup(message) {
    $(function () {
        $("#dialog").html(message);
            $("#dialog").dialog({
            title: "New words result",
            resizable: true,
            height: "auto",
            width:"900px",
            buttons: {
               },
            modal: true
        });
    });
};

C#

string sqlconn = ConfigurationManager.AppSettings["vConnString"].ToString();
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(sqlconn);
string QUERY = "Sproc_FindNewWords";
SqlCommand cmd = new SqlCommand(QUERY, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AM_AssetID", ddlGroup.SelectedItem.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
StringBuilder sb = new StringBuilder();

if (dt.Rows.Count > 0)
{
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        if (dt.Rows[i]["val"].ToString()!="")
        {
            sb.Append("<span>" + dt.Rows[i]["val"].ToString() + "</span>,&nbsp;"); 
        }               
    }          
}

string message = sb.ToString();         
ScriptManager.RegisterStartupScript(this,GetType(), "Popup", "ShowPopup('" + message + "');", true);

我想知道$("#dialog").html(message);的确切长度是多少 当消息文本很小时,它可以正常工作,而当文本太大时,它就无法正常工作。

Jquery Dialog 上显示结果的任何其他方式请提出建议。

【问题讨论】:

  • 你可以通过console.log(message.length);来检查消息的长度。使用 Web 服务时可能会出现长度消息。您使用的是 Web 服务吗?
  • 不,我在 Button_Click 事件上调用函数
  • 你试过这个 - roam.be/notebook/2012/…,在 Jquery 对话框中换行,或者在宽度上使用 auto 而不是 900px

标签: c# jquery asp.net jquery-dialog


【解决方案1】:

在 aspx 中取 Div ;

<div id="divmessage" style='display:none' runat='server'/>

在 aspx.cs 中

divmessage.innerHTML=message;
ScriptManager.RegisterStartupScript(this,GetType(), "Popup", "ShowPopup();", true);

在 jquery 中

function ShowPopup() {
var message=$("#divmessage").html();
if(message.length>0)
$(function () {
    $("#dialog").html(message);
        $("#dialog").dialog({
        title: "New words result",
        resizable: true,
        height: "auto",
        width:"900px",
        buttons: {
           },
        modal: true
    });
});

};

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 2011-04-27
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多