Drkcore

22 05 2013 Python Tweet

PythonScriptでjQueryを扱う

次回のShizuoka.pyはサーバーサイド寄りの演題が多めなので、カウンターとしてフロントエンド寄りのネタでもやろうかなと思いPythonScriptをいじっている。

PythonScriptでjQueryを使うのは簡単。jQueryとラッパーを呼び出しておけばJでアクセスできる。

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>PythonScript & jQuery</title>
    </head>
    <body>
      <div id="mydiv">click      
      </div>
      <script src="pythonscript.js"></script>
      <script src="jquery.js"></script>
      <script src="jquery.py.js"></script>
      <script src="app.py.js"></script>
    </body>
</html>

app.py

J()でjQueryのラッパーオブジェクトを作れるが、jQueryオブジェクトはj属性で参照されるので注意。

class Model():
    def __init__(self, tag):
        self.el = J(tag)
        self.el.bind("click", self.el, self.say)

    def say(self):
        d = J('<p>:-)</p>')
        self.el.append(d.j)
        print "hello PythonScript"

m = Model('#mydiv')

pythonscript & jQuery

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021