我知道有很多关于此的帖子,但我已经尝试了每一个,但没有一个有效!
我有一个使用 Visual Studio 2010 运行的 aspx 和 aspx.cs 页面。
在我的 aspx 页面上,我有一张桌子
<table id="viewPendingTable" runat="server"></table>
在 aspx.cs 页面上,表中加载了数据。这工作正常,没问题。加载页面后,该表将包含我需要的动态添加的数据。
我正在使用 jquery dataTables 使用标准设置我的表格样式
$(document).ready(function () {
$('#viewPendingTable').dataTable({
"bJQueryUI": true,
});
});
当我直接在 html 中创建带有虚拟信息的测试表时,数据表会根据需要正确显示。但是当我将 jquery 脚本应用于动态表时。什么都没发生。根据需要显示动态数据,但不存在数据表(搜索功能、样式等)。
现在我怀疑这是因为脚本是在表格填充数据之前运行的。
这是我开始执行任务的地方,即在 aspx.cs 运行并填充表之后强制 jquery/javascript 运行。
但我失败了......所以作为一个测试,我想我会运行一个 alert('YAAY'); 从 c# 端使用注册的启动脚本。但是没有用,那是行不通的。
所以有人可以告诉我为什么这不起作用。
我尝试了多种不同的启动脚本方式!
我的aspx是:
<table id="viewPendingTable" runat="server"></table>
<script type="text/javascript" language="javascript" id="ShowTable">
<!--
loadTable();
function loadTable() {
$(document).ready(function () {
$('#viewPendingTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});
alert('ALEX');
document.getElementById("table_id").width = "100%";
}
//-->
</script>
而我的 aspx.cs 是:
protected void Page_Load(object sender, EventArgs e)
{
loadMyTable();
ClientScriptManager a = null;
a.RegisterStartupScript(GetType(), "anotherkey", "alert('ASDFASDFASDF');", true);
a.RegisterStartupScript(GetType(), "anfgsdgsderkey", "alert('MOTHER');", false);
a.RegisterStartupScript(this.GetType(), "AKey", "loadTable();", true);
ClientScript.RegisterStartupScript(GetType(), "MyScript", "<script language=javascript>" + "alert('Hello ASP.NET'); }</script>");
ScriptManager.RegisterStartupScript(this.Page, GetType(), "script", "alert('Success!');", true);
Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "alert('AAA');", true);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script",
"alert('a');" +
"$(document).ready(function (){" +
"$('#viewPendingTable').dataTable({" +
"\"bJQueryUI\": true" +
"\"sPaginationType\": \"full_numbers\"" +
"});" +
"}); alert('b'); document.getElementById('viewPendingTable').width = 100%", true);
}
我已经尝试了更多方法来尝试在页面加载后运行 javascript,但是他们因失败而感到愤怒而迷失了方向。
有人请帮忙!
为什么我的简单 javascript 警报没有运行?
即使我让他们工作......数据表是否可以通过在页面加载后执行 jquery 来正确设置样式?
谢谢你的时间
亚历克斯
ps 没有关于 asp:gridView 或 asp:DataTable 的评论,因为它失败了,我几天前在上面发布了一个问题,没有人回复。如果你想看看 点击这里