Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created November 25, 2011 09:00
Show Gist options
  • Save violetyk/1393085 to your computer and use it in GitHub Desktop.
Save violetyk/1393085 to your computer and use it in GitHub Desktop.
[cakephp]jsヘルパー、関数をbufferしてgetしたjqueryオブジェクトにeventを結びつける
<?php
// 入力タイプの切替イベント。
$func = '
function changeType() {
var type = parseInt($("#SurveyQuestionType").val());
if(type <= 3){
$(".question_item").show("normal");
} else {
$(".question_item").hide("fast");
}
}
changeType();
';
// getしたjqueryオブジェクトをclickイベントに結びつける。
$js->buffer($func);
$js->get("#SurveyQuestionType");
$js->event("click", 'changeType();');
// 質問の選択肢の追加イベント。
$js->get("#btn_add_question_item");
$callback = '
$(".question_item:last").after($(".question_item:last").clone());
';
$js->event("click", $callback);
// バッファを出力。
e($js->writeBuffer(array('inline' => true)));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment