我正在尝试创建一个页面,当您单击“引用”按钮时生成引用,然后您可以使用twitter按钮发布引用。 Here是twitter按钮的链接。
twitter按钮允许您通过更改“数据文本”属性来发送所需的特定文本。
我想使用我的“引用”按钮生成引号,同时更改我的推文按钮的数据文本属性,以便我可以点击推特按钮并发推特定报价。
到目前为止,我有点击功能的一部分:
import pygame
# --- constants ---- UPPERCASE
SIZE = WIDTH, HEIGHT = 720, 480
SPEED = [2, 2]
# Colours
BLACK = (0,0,0)
BLUE = (0,0,255)
GREEN = (0,200,0)
RED = (200,0,0)
GREEN_BRIGHT = (0,255,0)
RED_BRIGHT = (255,0,0)
# --- functions ---
def text_objects(text, font):
text_surface = font.render(text, True, BLACK)
return text_surface, text_surface.get_rect()
def game_intro():
large_text = pygame.font.Font('freesansbold.ttf', 115)
text_surf, text_rect = text_objects("Broom!", large_text)
# center using screen
text_rect.center = screen.get_rect().center
button_green_rect = pygame.Rect(75,400,100,50)
button_red_rect = pygame.Rect(550,400,100,50)
intro = True
while intro:
# --- events ---
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
intro = False
mouse = pygame.mouse.get_pos()
# --- draws ----
screen.fill(BLUE)
screen.blit(text_surf, text_rect)
#Button
if button_green_rect.collidepoint(mouse):
pygame.draw.rect(screen, GREEN_BRIGHT, button_green_rect)
else:
pygame.draw.rect(screen, GREEN, button_green_rect)
if button_red_rect.collidepoint(mouse):
pygame.draw.rect(screen, RED_BRIGHT, button_red_rect)
else:
pygame.draw.rect(screen, RED, button_red_rect)
pygame.display.flip()
clock.tick(15)
# --- main ---
pygame.init()
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption("BETA::00.0.1")
clock = pygame.time.Clock()
game_intro()
pygame.quit()
其中j是引用数组的索引,但我似乎无法使其工作。
编辑:这是一个有效的演示:http://codepen.io/michaelaharvey/pen/wMzGJR
答案 0 :(得分:2)
我将变得与众不同并建议使用jquery数据方法https://api.jquery.com/data/
$("a").data("text", quotes[j]);
答案 1 :(得分:1)
您应该可以使用.attr
$("a").attr("data-text", quotes[j]);
答案 2 :(得分:1)
'://platform.twitter.com/widgets.js`` loads an
iframe into
。asdf , removing exisiting
一个element within
。asdf . When attempting to access
一个element within
iframe`
Uncaught SecurityError: Failed to read the 'contentDocument'
property from 'HTMLIFrameElement':
Sandbox access violation: Blocked a frame at
"http://stacksnippets.net" from accessing a frame at
"http://platform.twitter.com".
Both frames are sandboxed and lack the "allow-same-origin" flag.
已登录console
答案 3 :(得分:1)
如果您检查DOM,则找不到任何a
标记,但.data,.attr,.prop
将要求该元素出现在DOM中
存储与匹配元素关联的任意数据,或者在指定数据存储中返回匹配元素集中第一个元素的值。