ラベル jQuery の投稿を表示しています。 すべての投稿を表示
ラベル jQuery の投稿を表示しています。 すべての投稿を表示

火曜日, 5月 13, 2014

Javascript (jQuery) から PHP の関数を呼び出す

ボタンを押したときに、PHP の関数を呼び出したいとします。

Form を使って PHP ファイルを読み込み、ページ全体を書き直すという手段もありますが、ある関数だけを呼び出したいときなど、ajax を使うと PHP 関数を呼び出してページ側で返り値を得ることができます。

このように、url でファイル名を指定して、success で返り値 results として引き渡してやります。

PHP ファイル側では、渡したい値を echo などで表示します。

これで PHP の関数をページから呼び出すことができます。


木曜日, 5月 01, 2014

HTMLエディターを1行で書く

HTMLエディターを1行で書いてみました。

要するに、書いたHTMLがそれっぽく見えればWYSIWYGってわけですよね。

じゃあ、書いたものをそのままブラウザ表示すりゃいいわけじゃないですか。

これを動かすと、何もないテキストボックスが下のほうに表示されます。

適宜 HTMLコードを入力してみましょう。

画面上部に結果が表示されます。

リアルタイムでHTMLコードが編集できます。

ちょっとしたプレビューにも使えます。

金曜日, 2月 10, 2012

Newline in select-option tags

Our site had a list of fonts available for our clients. The list included, European and Cyrillic fonts. We put them in a drop-down list.

List of fonts:
     European
     Cyrillic

Then, it turned out to be that Cyrillic fonts were included in European fonts. We had to select/deselect both at the same time. The trouble is, the HTML's select's option does not take br tags, or new lines. All lines have to be in a single line. Here is a jQuery code that select/deselect European and Cyrillic fonts at the same time. The code hooks any click on the European fonts to a handler that select/deselect Cyrillic fonts.
 
    $('#European').live("click",function(){
     var selected=$('#European').attr("selected");
     if(selected=="selected") 
  {
      $('#Cyrillic').attr("selected","selected");      
  }
     else
  {
      $('#Cyrillic').attr("selected",false);      
  }    
 });

Here is a word of caution; we had yet another problem with the Cyrillic option with the reset operation. The Cyrillic option has to be deselected manually.
 
    // de-selects the Cyrillic option.
    $("#reset").click(function(){
         $('#Cyrillic').attr("selected",false);      
 });

Flask の Blueprint のテンプレート問題

  Flask の Blueprint は、ルート、静的ファイル、テンプレートをまとめて管理できます。しかし、テンプレートが指定できません。 ここでは、Blueprint の template_folder の問題点と回避策を説明します。 Blueprint のテンプレート問題...