我想将类添加到现有表行中,以在单击行时更改行颜色。
现在我的代码如下。
为网格订阅#!/bin/bash
id=
while read n line; do ## read each line from process substitution
a=( $line ) ## split line into array
for i in ${a[@]}; do ## search array, set id
[ "${i%=*}" = "identity" ] && id="${i##*=}"
done
echo "device=$n" ## output device=
printf " %s\n" ${line[@]} ## output setting=value (unquoted on purpose)
printf " \$device[%s][%s]\n" "$n" "$id" ## $device[0][identity]
done < <(tr '\n' '_' < "$1" | tr -s ' ' | sed -e 's/__/\n/g' -e 's/_//g')
。
$ bash mikrotik_parse.sh mikrotik
device=0
interface=ether1
address=172.16.127.2
address4=172.16.127.2
address6=fe80::ce2d:e0ff:fe00:05
mac-address=CC:2D:E0:00:00:08
identity="myrouter1"
platform="MikroTik"
version="6.43.8
(stable)"
$device[0]["myrouter1"]
device=1
interface=ether2
address=10.5.44.100
address4=10.5.44.100
address6=fe80::ce2d:e0ff:fe00:07
mac-address=CC:2D:E0:00:00:05
identity="myrouter4"
platform="MikroTik"
version="6.43.8
(stable)"
$device[1]["myrouter4"]
device=3
interface=ether4
address=fe80::ba69:f4ff:fe00:0017
address6=fe80::ba69:f4ff:fe00:0017
mac-address=B8:69:F4:00:00:07
identity="myrouter2"
platform="MikroTik"
version="6.43.8
(stable)"
$device[3]["myrouter2"]
答案 0 :(得分:1)
如果可以获取元素,则可以使用classList属性:
https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
element.classList.add("anotherclass");
答案 1 :(得分:0)
我建议您首先获取所单击行中的单元格。例如,您可以通过首先获取目标元素(单击的单元格),然后获取其父级(行),然后从父级获取子级(行中的所有单元格)来实现此目的。然后遍历它们并更改其样式。重要的是使用单元格,而不是行本身,因为单元格的z索引比行高。
var children = $($(e.target)[0].parentElement).children();
for (var key in children) {
if(children.hasOwnProperty(key))
children[key].style["background-color"] = "red";
}
您当然也可以使用$(children[key]).addClass("yourClass")