本文整理汇总了Golang中honnef/co/go/js/dom.Element.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:Golang Element.GetAttribute方法的具体用法?Golang Element.GetAttribute怎么用?Golang Element.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类honnef/co/go/js/dom.Element
的用法示例。
在下文中一共展示了Element.GetAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addClass
// addClass adds class to the given element. It retains any other classes that
// the element may have.
func addClass(el dom.Element, class string) {
newClasses := class
if oldClasses := el.GetAttribute("class"); oldClasses != "" {
newClasses = oldClasses + " " + class
}
el.SetAttribute("class", newClasses)
}
示例2: removeClass
// removeClass removes the given class from the element it retains any other
// classes that the element may have.
func removeClass(el dom.Element, class string) {
oldClasses := el.GetAttribute("class")
if oldClasses == class {
// The only class present was the one we want to remove. Remove the class
// attribute entirely.
el.RemoveAttribute("class")
}
classList := strings.Split(oldClasses, " ")
for i, currentClass := range classList {
if currentClass == class {
newClassList := append(classList[:i], classList[i+1:]...)
el.SetAttribute("class", strings.Join(newClassList, " "))
}
}
}