我一直在寻找答案,却找不到有效的答案。
基本上,我有一个函数可以发布到facebook墙或twitter提要,但点击功能只触发一次。
下面是代码:
$('.social a').on 'click', (e) ->
e.preventDefault()
book = book.collectMeta $(@).parents('.book')
if $(@).hasClass 'fb-share'
postFacebook book
if $(@).hasClass 'twitter-share'
postTwitter book被触发的collectMeta函数如下:
book =
collectMeta: (dom) ->
# Helper function that collects data of a book and prepares it
# for sharing on sociall media
# The argument for this function accepts the parent DOM Object
# that searches for the appropriate Meta Data
$title = dom.find '.book-title'
title = helper.cleanWhite $title.text()
$author = dom.find '.book-author'
author = helper.cleanWhite $author.text()
$description = dom.find '.book-description'
description = helper.cleanWhite $description.text()
description = helper.trimText(description, 140)
$link = dom.find '.book-link'
link = glob.baseUrl() + $link.attr 'href'
$image = dom.find '.book-image'
image = glob.baseUrl() + $image.attr 'src'
return book =
title: title
caption: author
description: description
link: link
image: image第一次点击后收到的错误是: book.collectMeta不是一个函数
任何帮助都是非常感谢的!
发布于 2014-02-10 20:01:38
您的第一个单击是调用一个不存在的函数:book.collectMeta。这会扼杀你的脚本,所以在那之后的任何事情都是行不通的。
在我看来,这种情况可能会发生,因为您正在重写以下行中的book变量:
book = book.collectMeta $(@).parents('.book')因此,第一次单击将起作用,但随后的单击将不再起作用,因为图书不再具有与其相关的功能。
https://stackoverflow.com/questions/21686671
复制相似问题