使用 Jquery 将 Colspan = "2" 替换为 Colspan = "4"

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1393901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:20:41  来源:igfitidea点击:

Replacing Colspan = "2" with Colspan = "4" using Jquery

jquery

提问by Manoj Singh

VenueID:场地编号:3

I want to replace first Colspan="2" with Colspan="4" in my first TR not in complete page using JQuery.

我想在我的第一个 TR 中用 Colspan="4" 替换第一个 Colspan="2" 而不是使用 JQuery 的完整页面。

Thanks.

谢谢。

Best Regards, MS

最好的问候,女士

回答by gnarf

This jQuery should handle the condition of finding a td with colspan 2 in the first tr of any table and set its colspan to 4.

这个 jQuery 应该处理在任何表的第一个 tr 中找到一个带有 colspan 2 的 td 并将其 colspan 设置为 4 的条件。

$("table tr:first td[colspan=2]").attr('colspan',4);

The better thing to do would be to just fix your HTML to produce colspan=4

更好的做法是修复您的 HTML 以生成 colspan=4

回答by n1313

First of all, you forgot to close one of your <tr>'s. Second, you'll need a unique id or classname attached to that <td>to target it more easily. Third, use JQuery attr()method. Like this:

首先,你忘记关闭你<tr>的一个。其次,您需要附加一个唯一的 id 或类名以<td>更轻松地定位它。第三,使用JQueryattr()方法。像这样:

<tr>
     <td colspan="2" id="thatsmytd"></td>
</tr>

$('#thatsmytd').attr('colspan','4');

回答by kgiannakakis

Use :first selector:

使用 :first 选择器:

$("table tr:first")

回答by Phill Pafford

$("table tr:first").attr('colspan','4');

回答by Josh Stodola

$("table[id$=FormView1] tr:first td[colspan=2]").attr("colspan", "4");

回答by RPNinja

n1313's solution to changing the attribute is correct. If your question is how do you select the first row of a page that contains a cell with a colspan attribute then you just need to change your selector to something like this:

n1313修改属性的方案是正确的。如果您的问题是如何选择包含具有 colspan 属性的单元格的页面的第一行,那么您只需要将选择器更改为如下所示:

$("tr:first").find("td[colspan='2']:first").attr('colspan','4');

This is very specific. You may need to play with it to work exactly the way you need.

这是非常具体的。您可能需要使用它才能完全按照您需要的方式工作。