2014-05-17 2 views
0

안에 내가 옆에 PHP 스크립트를이 코드를 작성하는 방법에 어떤 생각을 자바 스크립트를 쓰기?PHP 코드

+1

첫 번째는 잘 작동 단지 것이다. 두 번째가 작동하지 않으면 따옴표 문제로 인해 가장 많이 발생합니다. 그들을 탈출해야 할 수도 있습니다. 네이티브 문자열이 많으면 많을수록 더 맛이 없으므로 이런 모든 것을 함께 피하는 것이 좋습니다. –

+0

예 ... 알아요 ... 이걸 수정하는 방법을 모른다는 것입니다 – user2491321

+1

위의 색상 코딩을 보면 약간의 힌트가 주어 집니까? – adeneo

답변

3

HTML 너무 많은 반향하지 마십시오입니다 대답, 당신은 echo

의 속기에 불과 그래서 이런 식으로 그것을 할 것입니다없는 echo 문 내부 <?=을 사용하고 있기 때문에 코드가 실패 된 이유, 대신 mouseovermouseout 이벤트를 사용

<a href = "javascript:void(0)" onclick = "clicked(<?=$the_job_id;?>, <?=$the_job_id;?>)"> 
    <img src='img/remove.png' onmouseover="this.src='img/remove_light.png'" onmouseout="this.src='img/remove.png'" /> 
</a> 

<script> 
    //If you are sure that lightposid and fadeposid are going to be same 
    //than 1 parameter is sufficient 
    function clicked(lightposid, fadeposid) { 
     document.getElementById('lightpos' + lightposid).style.display='block'; 
     document.getElementById('fadepos' + fadeposid).style.display='block'; 
    } 
</script> 

그리고 하나님을 위해

사용 :hover 의사 ...

그리고 당신은 화장실하는 경우 king 대신 img 태그의 URL을 바꾸는 대신 함수를 사용하십시오. 의 값으로 위의 데모에서 사용하고 1, 1 :

Demo

(내가 lightpos1 id가진 fadepos1을 요소가 없기 때문에 콘솔 로그는 정의되지 않은 반환됩니다) <?=$the_job_id;?>. 그래서 그들은 .. 실제 작업 식별자가 될 것입니다


당신은 당신의 CSS에서 이런 걸의 img 태그를 제거 이제

<a href = "javascript:void(0)" onclick = "clicked(<?=$the_job_id;?>, <?=$the_job_id;?>)"> 
    <span class="remove"></span> 
</a> 

같은 span 요소로 대체 ​​사용하고자하는 경우 모든

.remove { 
    display: inline-block; 
    height: 30px; 
    width: 30px; /* Set height and width according to your requirements */ 
    background-image: url('URL_OF_THE_REMOEV_IMAGE_GOES_HERE'); 
    background-repeat: no-repeat; 
    outline: 1px solid red; /* Remove this after you set the height and width correctly */ 
    vertical-align: middle; /* Not sure but I think you will need this */ 
} 

.remove:hover { 
    background-image: url('REMOVE_LIGHT_PNG_URL_GOES_HERE'); 
} 
2

먼저 큰 따옴표 (") 또는 전혀 quotesfor 변수를 사용, 작은 따옴표 (')를 사용하지 말아.

코드에 가변 길이 $ the_job_id을 작은 따옴표로 묶어 입력하십시오.

이 코드보십시오 :

<?php 
echo '<a href ="javascript:void(0)" onclick ="clickFunc()"><img src="img/remove.png" onmouseover="Over()" onmouseout="Out()"></a>' 
?> 

을 그리고이 스크립트를 사용하는 PHP 스크립트에

<script> 
function clickFunc() { 
    document.getElementById("lightpos'.$the_job_id.'").style.display = "block"; 
    document.getElementById("fadepos'.$the_job_id.'").style.display = "block" 
} 

function Over() { 
    this.src = "img/remove_light.png"; 
} 

function Out() { 
    this.src = "img/remove.png"; 
} 
    </script> 
+1

당신의'clickFunc()'가 정확하지 않습니다, 각 앵커 태그에 대해 그 함수를 반복 할 것입니까? –