2013-04-11 2 views
0

링크는이 예제에서 작동하지만 onClick은 아무 작업도 수행하지 않습니다. alert()에 productURL [i]를 표시하면 올바른 URL이 표시됩니다. 어떤 제안?JavaScript/jQuery에서 onClick 테이블 행이 작동하지 않습니다.

var output='<table class="api-table">'; 
output+='<thead><tr><th colspan="2">' + productSubstrateName + '</th></tr></thead>'; 
for (var i=0;i<productURL.length;i++) { 
output+='<tr>'; 
output+='<td style=\"cursor:pointer;\" onClick=\"'+productURL[i]+'\"><a href="'+productURL[i]+'">'+productSubstrateAmounts[i]+'</a></td>'; 
    output+='<td style=\"cursor:pointer;\" onClick=\"'+productURL[i]+'\"><a href="'+productURL[i]+'">'+productSubstratePrices[i]+'</a></td>'; 
    output+='</tr>'; 
} 

output+="</table>"; 

$('#'+outputdiv).append(output); 
+0

를 사용하여, 당신은'onClick' 할 것으로 예상하는 일이 –

+0

에 대한 귀하의 브라우저의 요소를 검사? – Archer

답변

3

는하지만 온 클릭은 아무것도하지 않는다.

당신이 뭔가를 할 필요가 있다면 당신이 함수

onClick="myFunction("'+productURL[i]+'")" 
를 호출 할 수 있습니다

onClick=\"'+productURL[i]+'\" 
     //--^^^^^^^^^^^---- 

.. 당신이 ..you 그냥 값을 인쇄가 아무것도하지 않은 becuase 아무것도하지 않는다

와 함수

function myFunction(obj){ 
    alert(obj); 
} 

당신은 할 사용하지 않아도 \

+0

그는 이미 세포 내부 앵커 태그가 있습니다. – Archer

+0

그것도 작동하지 않습니다. 이상한 것은 anchor ref.가 작동하고, 거기에 값을 인쇄하며, 링크를 클릭 할 때 배열 요소의 링크로 이동한다는 것입니다. 아무것도하지 않는 td onclick입니다. 앵커 태그는 테스트 목적으로 실제 링크가 유효한지 확인하기 위해 사용됩니다. –

+0

이 함수를 사용해보십시오. function myFunction (obj) { alert (obj); window.location = obj; } – bipen

0

초급 실수, 감사의 bipen, 나는 document.location.href을 잊었다. 당신은 또한 링크의 내용을 포장하고 있기 때문에 :-(

 for (var i=0;i<productURL.length;i++) { 
      output+='<tr>'; 
      output+='<td style="cursor:pointer;" onClick="document.location.href=\''+productURL[i]+'\';"><a href="'+productURL[i]+'">'+productSubstrateAmounts[i]+'</a></td>'; 
      output+='<td style="cursor:pointer;" onClick="document.location.href=\''+productURL[i]+'\';"><a href="'+productURL[i]+'">'+productSubstratePrices[i]+'</a></td>'; 
      output+='</tr>'; 
     } 
관련 문제