링크를 클릭 할 때 특정 div를 인쇄하는 코드가 있지만 작동하지 않는 것 같습니다.자바 스크립트 인쇄 코드가 작동하지 않습니다
코드의 목적은 "HEJ"라는 링크를 클릭하면 mydiv라는 내 div를 인쇄해야하는데, 그렇게해야하는 스크립트를 찾았지만 제대로 작동하지 않는 것 같습니다.
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body><p style="font-family:arial">');
mywindow.document.write(data);
mywindow.document.write('</p></body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
</script>
위의 코드는 내가 인터넷 어딘가에있는 자바 스크립트, 그리고 아래의 코드는 자바 스크립트 코드를 트리거 HTML입니다.
<div id="mydiv">
Test
</div>
<a href="#" onclick="PrintElem('.mydiv')" />HEJ</a>
나는 또한 제거하려고 시도했습니다. onclick 요소에서 mydiv 전에는 작동하지만 아무 것도 작동하지 않습니다. 링크를 클릭해도 아무런 변화가 없습니다.
여러분이이 문제로 나를 도울 수 있기를 바랍니다.
내가 완전히 코드를 통과 havent 한하지만 당신은 –
를 작동하는 경우 Onfortunately가 작동하지 않았다 '#mydiv'와 '.mydiv를'교체 시도하고 볼 수 있습니다 : –
이 @jedifans 답변 –