2012-06-28 2 views
-2

다음 스크립트가 작동하지 않습니다. 링크를 추가하려면 어떻게해야합니까? jno = "97856483"; dispTitle = "새 책"; dispAuthor = "authorname";자바 스크립트에서 PHP 스크립트로 링크 추가하기

document.getElementById('popups').innerHTML = ''; 
//Add link to add this book: 
var url = encodeURIComponent(jno) + "&tt=" + encodeURIComponent(dispTitle) + "&at=" + encodeURIComponent(dispAuthor); 
//document.writeln(url); 
document.getElementById("addLink").innerHTML = "<a href='memaccountentry.php?isbn='+ url>Add book</a>" ; //This one just appends the word url. 
//window.location.href = 'memaccountentry.php?isbn=' +jno +'&tt=' +dispTitle+'&at=' +dispAuthor;   //I know this is working, but not a right way to do. 
//I need to put a href link to go to the next page. 
//ajax.open('GET', 'memaccountentry.php?isbn=' +jno +'&tt=' +dispTitle+'&at=' +dispAuthor', true); 

답변

4

인용문을 올바르게 열고 닫아야합니다.

document.getElementById("addLink").innerHTML = "<a href='memaccountentry.php?isbn="+ url +"'>Add book</a>" ; //This one just appends the word url. 
+0

결코 닫히지 않는 memaccountentry 앞에 작은 따옴표가 하나 있습니다. –

+0

@ Sonal-Patelia : 고맙습니다. – Jocelyn

+0

고마워. 이제 알았다. 나는 몇 시간 동안이 단순한 것을 찾고 있었다. 투표까지! –

1

그것은 당신이 제대로 문자열을 포맷하지 않았다 같습니다
는 것을보십시오.

이것이 원하는 것이 아니라면, 완전히 혼란 스럽습니다.

document.getElementById("addLink").innerHTML = "<a href='memaccountentry.php?isbn='" + url + ">Add book</a>"; 
+0

그냥 memaccountentry.php? isbn =을 표시합니다. URL은 링크에 추가되지 않습니다. –

관련 문제