将php-variable转移到javascript变量

时间:2013-01-17 12:41:02

标签: php javascript html

我已合并了这个简单的datetimepicker:http://trentrichardson.com/examples/timepicker/#rest_examples

所以看起来

<?php $tabname = "brightness"; ?>
<script type="text/javascript">
$('#datumstartbrightness').timepicker();
</script>
...
<input type="text" name="datumstart<?php echo $tabname; ?>" 
                id="datumstart<?php echo    $tabname; ?>"/> 
...

使用此代码可以正常工作并显示datetimepicker!

但有了这个......

<?php $tabname = "brightness"; ?>
<script type="text/javascript">
$('#datumstart<?php echo $tabname; ?>').timepicker();
</script>
...
<input type="text" name="datumstart<?php echo $tabname; ?>" id="datumstart<?php echo     $tabname; ?>"/> 
...

不显示DateTimePicker。这条线可能有什么问题

$( '#datumstart')timepicker();

1 个答案:

答案 0 :(得分:3)

在调用jQuery函数之前,你需要先做就绪状态:所以试试这个:

<script type="text/javascript">
$(function() {
   $('#datumstart<?php echo $tabname; ?>').timepicker();
});
</script>