简体   繁体   English

使用带有数据ID标记的Javascript添加属性COLSPAN

[英]Adding an Attribute COLSPAN using Javascript Using an data-id Tag

Good Day! 美好的一天! I am only new in programming javascript I have this problem theres a table Tag with a Theader with an Attribute of data-id now I just want to add a Colspan Dynamically using this data-id tag to find the specific Column to add a COLSPAN attribute 我只是编程javascript的新手,所以我有这个问题,有一个带有Theader的表格标签,其属性为data-id,现在我只想使用此data-id标签动态添加一个Colspan来查找要添加COLSPAN属性的特定列

I've created this code of mine 我已经创建了我的这段代码

 $('th[data-id="param_name_3_check"]').remove();

This is to remove a table header in a Table in Javascript, and try to use the following code to add some attribute. 这是为了删除Javascript表中的表头,并尝试使用以下代码添加一些属性。

$('th[data-id="param_name_1_value"]').createAttribute("colspan", "9");

But theres an error, is it possible to add an Attribute via data-id? 但是存在错误,是否可以通过data-id添加属性?

Thanks 谢谢

You can set attribute like this: 您可以这样设置属性:

$('th[data-id="param_name_1_value"]').attr("colspan", "9");

fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM