나는 레일 프로젝트를하고 있습니다. 여기에 내 문제가 온다 : 내 .haml 파일에 button_to 태그가 :js in rails : onclick에 관하여
= button_to "Add", add_problem_path(paper, :problem_id => problem.id), :class => 'essay_problem', :id => problem.id, :remote => true, :onclick => 'new function() { if($(".essay#3").val() == "xxxx"){ alert("Please add the essay first!"); return false; } }'
제가하고 싶은 것은이 add_problem_path에 게시하기 전에 확인 후 전달되는 경우, onclick()
에 의한 검증을 만드는 것이 add_problem_path에 게시물을 올리거나 경고 만하고 아무것도하지 않습니다. 어떻게해야합니까? HAML 파일에 자바 스크립트 :
알았습니다. 'onclick'이 false를 반환하면 button_to는 add_problem_path에 게시되지 않습니다. 이전에는 onclick 이벤트에서 반환을 의미하는 onclick 이벤트에서 false를 리턴합니다. 도와 줘서 고마워! – kgtong