gpt4 book ai didi

javascript - 使用jquery和c#从span检索数据

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

我正在尝试从跨度中检索 td 内的一些值。我有这个功能:

function reorder() {
alert("Entrando en reorder");
strorder = "";
var totalid = $('#ctl00_ContentPlaceHolder1_grdResultados tr td input').length;
alert(totalid);
for (var i = 0; i < totalid; i++) {
strorder = strorder +$('#ctl00_ContentPlaceHolder1_grdResultados tr td span')[i].text()+"*"+ $('#ctl00_ContentPlaceHolder1_grdResultados tr td input')[i].getAttribute("value") + "|";
alert("strorder1");
}
//strorder = window.location.href;
alert("strorder2");
}

源代码是这样的(一段代码):

<table class="table table-hover tablaDimensiones" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_grdResultados" style="border-collapse:collapse;">
<tr>
<th scope="col">
<a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados&#39;,&#39;Sort$titulo&#39;)">Título</a>
</th>
<th scope="col">Opciones</th>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_lblTitulo">Dimension1</span>
<input type="hidden" name="ctl00$ContentPlaceHolder1$grdResultados$ctl02$hdnid" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_hdnid" value="1" />
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEditar" title="Editar" class="btn btn-default" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEditar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</a>
&nbsp;
<a onclick="return confirm(&#39;¿Desea elimnar la dimensión?&#39;);" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEliminar" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEliminar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>

</td>
</tr>
<tr>

我该怎么办呢?,因为这样我就没有得到我想要的。问候

最佳答案

我相信下面的示例就是您所寻找的,您的代码几乎是正确的,您应该稍微组织一下。

注意:代码中唯一的错误是在长行中:

strorder = strorder +$('#ctl00_ContentPlaceHolder1_grdResultados tr td span')[i].text()+"*"+ $('#ctl00_ContentPlaceHolder1_grdResultados tr td input')[i].getAttribute("value") + "|";

希望这有帮助。

function reorder() {
var strorder = "";
var table_spans = $('#ctl00_ContentPlaceHolder1_grdResultados span[id^="ctl00_ContentPlaceHolder1"]');
var table_inputs = $('#ctl00_ContentPlaceHolder1_grdResultados input');

for (var i = 0; i < table_inputs.length; i++)
{
var span_text = table_spans.eq(i).text();
var input_value = table_inputs.eq(i).val();

strorder += span_text + "*" + input_value + "|";
}

console.log(strorder);
}

reorder();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<table class="table table-hover tablaDimensiones" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_grdResultados" style="border-collapse:collapse;">
<tr>
<th scope="col">
<a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados&#39;,&#39;Sort$titulo&#39;)">Título</a>
</th>
<th scope="col">Opciones</th>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_lblTitulo">Dimension1</span>
<input type="hidden" name="ctl00$ContentPlaceHolder1$grdResultados$ctl02$hdnid" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_hdnid" value="1" />
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEditar" title="Editar" class="btn btn-default" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEditar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</a>
&nbsp;
<a onclick="return confirm(&#39;¿Desea elimnar la dimensión?&#39;);" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEliminar" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEliminar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>

</td>
</tr>
</table>

关于javascript - 使用jquery和c#从span检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38551202/

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