26. onclick이벤트 이용하기 -php-

 

주석 만들기

onClick명령 후에 <?=$변수?>형식이 올 때는 html 주석만으로는 안 되고 아래와 같이 //를 사용해서 변수 부분의 주석을 처리해야한다.

<!-- <input type="button" value="문제 목록" onClick="goback_list(<?=//$data[q_idx]?>,<?=//$page?>,<?//=$_GET[qlist]?>);">

-->

 

onclick으로 get변수와 함께 페이지 이동하기

따옴표 사용에 유의해야 한다.

<input type="button" value="문제 목록" onClick="location.href='question_list.php?page=<?=$_GET[page]?>';">

//변수가 여러 개인 경우

<input type="button" value="글수정" onClick="location.href='ques_modify.php?q_idx=<?=$data[q_idx]?>&amp;page=<?=$_GET[page]?>&amp;qlist=<?=$_GET[qlist]?>';">

 

onclick으로 js함수에 매개 변수 전달하기

따옴표 사용에 유의해야 한다. 3개의 매개 변수 전달. goback_list라는 자바 함수를 호출한다.

<input type="button" value="문제 목록" onClick="goback_list('<?=$data[q_idx]?>','<?=$page?>','<?=$_GET[qlist]?>');">

 

자바스크립트 함수의 예

<script>

function ques_delete(q_idx){

if(confirm('삭제 하시겠습니까?')){ // q_idx가 그냥 변수처럼 사용된다. $ 이런 거 없다.

location.href='ques_delete.php?q_idx='+ q_idx"; // 문자열 연결로 +사용한다.

}

}

</script>

 

자바스크립트에서 함수와 조건문 사용.

<script>

function goback_list(q_idx, page, qlist) //매개변수 3개 사용

{

if(qlist=='list'){ //qlist가 변수처럼 사용된다.

document.write('<?=$_GET[qlist]?>');

location.href="question_list.php"; //페이지 이동하기.

}else if(qlist=='lista'){

//php 변수를 사용해 get방식으로 값 전달. href를 사용하는 경우엔 &대신 &amp;를  써도 됨.(같은 거지만...) location.href="ques_list.a.php?q_id=<?=$data[q_id]?>&amp;page=<?=_GET[page]?>";

 

}else if(qlist=='listb'){

location.href="ques_list.a.php?q_idgroup=<?=$data[q_group]?>&amp;page=<?=_GET[page]?>";

}

}

</script>

onclick 이벤트시 php함수를 부르게 하는 방법이 있단다.

 

코딩을 객체화시켜서 작업을 하면 된다.

php에서

class A {

function zipcode() { //php함수를 만들고

:

}

}

 

$A= new A(); //$A를 클래스를 만든다는 말인 것같다.

 

사용 예

<img src='../../images/member/btn_findaddr2.gif' border='0' align='absmiddle' alt='찾기'

onclick='<?=$A->zipcode();?>'>

 

href, location.href, location.replace()의 차이

href: html에서 사용.

location.href: 자바에서 사용. history.back()이 된다.

location.replace(): 자바용. history.back()이 안된다고 하네..

Posted by star story :

Snippet :: Code View :: "+location.href+'
'+b+"

");top.consoleRef.document.close()}$(".snippet-container").each(function(b){$(this).find("a.snippet-text").click(function(){var d=$(this).parents(".snippet-wrap").find(".snippet-formatted");var c=$(this).parents(".snippet-wrap").find(".snippet-textonly");d.toggle();c.toggle();if(c.is(":visible")){$(this).html("html")}else{$(this).html("text")}return false});$(this).find("a.snippet-window").click(function(){var c=$(this).parents(".snippet-wrap").find(".snippet-textonly").html();a(c);$(this).blur();return false})});$(".snippet-toggle").each(function(b){$(this).click(function(){$(this).parents(".snippet-container").find(".snippet-wrap").toggle()})})});