문제

I have a field called exp delivery date so i need the user to put a date in and then press print. However the print function doesn't catch the inputted text. So i did this:

$('#exp').live('change',function(){         
                var deliv = $('#exp').val();
                $('#delivDate').replaceWith("<p id='delivDate'>" + deliv + "</p>");
                $('#exp').val('');
            }); 

'#exp' is the input id and '#delivDate' is a <p> tag right next to the input. I'm only doing this so the .print() will catch it?

Can anyone think of a better way to do this? (it doesn't work in IE but does in FF by the way)

도움이 되었습니까?

해결책

Another way to accomplish this might be to use a jQuery plugin called Print Element which is able to print any specific element existing in the DOM. Or all of it.


If have trouble figuring out the mechanics on how to make the inputted text printable then here's a sample:

<textarea id="exp"></textarea>
<p id="delivDate"></p>

<script type="text/javascript">
$('#exp').live('change',function(){          
    var deliv = $('#exp').val();
    $('#exp').css('display', 'none'); // optional
    $('#delivDate').text(deliv);
    $('#exp').val(''); 
});
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top