本文整理匯總了Golang中github.com/gopherjs/jquery.JQuery.Attr方法的典型用法代碼示例。如果您正苦於以下問題:Golang JQuery.Attr方法的具體用法?Golang JQuery.Attr怎麽用?Golang JQuery.Attr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gopherjs/jquery.JQuery
的用法示例。
在下文中一共展示了JQuery.Attr方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: replace
func replace(t jquery.JQuery) {
href := t.Attr("href")
id := t.Attr("replace")
if len(id) == 0 || len(href) == 0 {
log.Printf("%s: replace fails id '%s' href '%s'", currentPath, id, href)
return
}
if page, doc, _ := mySite.Match(href); page == nil {
log.Printf("page not found %s", href)
} else {
idSelector := "#" + id
elt := jq(idSelector)
if elt.Length > 0 {
currentPath = href
bn := doc.BodyNodeById[id]
elt.ReplaceWith(bn.Markup(doc))
doc.AddBodyNodeEventListeners(document, bn)
// Select again since we've just changed it.
elt := jq(idSelector)
jqBind(elt)
elt.Call("foundation", "reflow")
// Change displayed page path without reloading page.
window.Get("history").Call("pushState", "object or string", "Title", href)
}
}
}
示例2: getDrawerListener
func getDrawerListener(c jquery.JQuery) (d canvas.Drawer, l canvas.Listener) {
id := c.Attr("id")
page := mySite.PageByPath[currentPath]
switch p := page.(type) {
case canvas.Interface:
var ok bool
if d, ok = p.Drawer(id); !ok {
log.Printf("%s: no canvas drawer for id '%s'", currentPath, id)
}
l, _ = p.Listener(id)
default:
log.Printf("%s: found canvas on page with no interface", currentPath)
}
return
}
示例3: canvasDraw
func canvasDraw(c jquery.JQuery) {
if c.Attr("width") == "" && c.Attr("height") == "" {
// Determine height from aspect ratio and parent's width.
aspect := 1.5 // 3 by 2 aspect ratio
attr := c.Attr("aspect")
if attr != "" {
_, err := fmt.Sscanf(attr, "%f", &aspect)
if err != nil {
panic(err)
}
}
parent := c.Parent()
w := parent.Width()
c.SetAttr("width", w)
c.SetAttr("height", float64(w)/aspect)
}
d, _ := getDrawerListener(c)
if d != nil {
go d.Draw(canvasContext(c))
}
}