>我有一个模板,其中包含一个复选框和一个从php检索的值。如何将 php 值与 {{filename}}
的值进行比较?如果两个值匹配,则将复选框设置为选中。
<script type="text/template" id="imageTemplate">
<div class="row gc_photo" id="gc_photo_{{id}}" style=" border-bottom:1px solid #ddd; padding-bottom:20px; margin-bottom:20px;">
<div class="checkbox">
<label>
<input onclick="return set_parentimage(this);" type="radio" name="primary_image" id="{{id}}_{{filename}}" value="{{id}}" {{#primary}}checked="checked"{{/primary}}/> <?php echo lang('main_image');?>
</label>
</div>
</div>
</script>
尝试使用我之前遇到的这个......有人向我建议。我的问题和你的问题很相似。在这里,我将一个值从PHP发送到javascript。希望对您有所帮助。
<?php
//somewhere set a value
$var = "a value";
?>
<script>
// then echo it into the js/html stream
// and assign to a js variable
spge = '<?php echo $var ;?>';
// then
alert(spge);
</script>