How can I declare a global variable in a PHP
file and access directly in jQuery
?
HTML
<script type="text/javascript">
var date_selected = <?php echo $from; ?>;
</script>
JS
$(function() {
alert("dsdsadasdas" + date_selected);
var date = date_selected;
var startDate;
var endDate;
});
Because on my test its not working.
您缺少引号
var date_selected = '<?php echo $a; ?>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.