Tôi muốn bao gồm jquery trong tập tin, nếu không có sẵn trong trang. Tôi có thể làm như thế nào?Bao gồm jQuery, nếu không bao gồm đã
tôi đã viết điều này, nhưng nó đem lại cho sản lượng không mong muốn.
<script type="text/javascript">
if ('undefined' == typeof window.jQuery) {
// jQuery not present
// alert("Jquery Unavailable");
<?php echo '<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>'; ?>
} else {
// jQuery present
alert("Jquery Available");
}
</script>
liên quan: http://stackoverflow.com/questions/6787569/best-way-to-avoid-including-stylesheets-external-js-more-than-once-in-a- trang –