用JavaScript创建网格容器
我是javascript新手,可以在WPF中创建类似“网格”的类容器吗? 不需要jQuery等,我需要在下面的XAML代码中创建类似网格的容器用JavaScript创建网格容器,javascript,xaml,Javascript,Xaml,我是javascript新手,可以在WPF中创建类似“网格”的类容器吗? 不需要jQuery等,我需要在下面的XAML代码中创建类似网格的容器 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xa
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="30*"></RowDefinition>
<RowDefinition Height="30*"></RowDefinition>
<RowDefinition Height="30*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100*">
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid x:Name="Grid2" Grid.Row="0" Grid.Column="0"></Grid>
</Grid>
您可以使用:
HTML标记:
<table id="grid1">
<tr class="row30">
<td class="column100">
<table id="Grid2"></table>
</td>
<td></td>
</tr>
<tr class="row30">
<td class="column100"></td>
<td></td>
</tr>
<tr class="row30">
<td class="column100"></td>
<td></td>
</tr>
</table>
在HTML中,只有Table元素提供类似的行为。它需要用css进行扩展,但是你可以创建一个类似网格的体验。如果您想要更多的功能,如排序、搜索和分页,我可以推荐jquerydatatables。它是免费的,易于使用和快速 这里有一些简单的JavaScript来装箱一张桌子
var container = document.getElementById("container");
var newInner = "<table>";
newInner += "<thead>";
newInner += "<tr>";
newInner += "<th>Column1</th>";
newInner += "<th>Column2</th>";
newInner += "</tr>";
newInner += "</thead>";
newInner += "<tbody>";
for (var i=0;i< 100;i++)
{
newInner += "<tr>";
newInner += "<td>Content" + i + "_1</td>";
newInner += "<td>Content" + i + "_2</td>";
newInner += "</tr>";
}
newInner += "</tbody>";
newInner += "</table>";
container.innerHTML = newInner;
var container=document.getElementById(“容器”);
var newInner=“”;
newInner+=“”;
newInner+=“”;
newInner+=“Column1”;
newInner+=“Column2”;
newInner+=“”;
newInner+=“”;
newInner+=“”;
对于(变量i=0;i<100;i++)
{
newInner+=“”;
新内部+=“内容”+i+“\u 1”;
新内部+=“内容”+i+“\u 2”;
newInner+=“”;
}
newInner+=“”;
newInner+=“”;
container.innerHTML=newInner;
只需使用html表格您是否查看了此处:也可以使用特定于供应商的网格标记,例如ms grid,但目前仅在IE中支持。如果是针对windows应用商店应用程序,这里有一个html和xaml比较:。
var container = document.getElementById("container");
var newInner = "<table>";
newInner += "<thead>";
newInner += "<tr>";
newInner += "<th>Column1</th>";
newInner += "<th>Column2</th>";
newInner += "</tr>";
newInner += "</thead>";
newInner += "<tbody>";
for (var i=0;i< 100;i++)
{
newInner += "<tr>";
newInner += "<td>Content" + i + "_1</td>";
newInner += "<td>Content" + i + "_2</td>";
newInner += "</tr>";
}
newInner += "</tbody>";
newInner += "</table>";
container.innerHTML = newInner;