dongzi1397 2016-03-28 09:46
浏览 31

使用php变量检查javascript中的变量[重复]

This question already has an answer here:

I have the php page with javascript code inside it. If I have php variable retrieved by back-end server, can it be passed in javascript code? For instance, if I want to check the flag(php variable) inside the javascript code, do I need to hardcode it inside the javascript? Below are the "checkServiceCategory"? (Should it be Dynamic or static)

<?php
foreach ($result as $id=>$value) {
if($value[0]->isServiceCategory)
return true;
}

OR

isEmptyUploadFile(function(r)
{
var checkServiceCategory=document.getElementById('category-group').value;
if(checkServiceCategory!=85 && (fileList == null || fileList.length == 0))
{
$("#uploadImgError").html('<em><span style="color:red"> <i class="icon-cancel-1 fa"></i> Please Upload at least one image!</span></em>');
location.href = "#uploadImgError";
return false;
}
else 
</div>
  • 写回答

3条回答 默认 最新

  • douzhuo8871 2016-03-28 09:51
    关注

    You can pass value from php to js like this.

    var js_var = '<?php echo $some_php_variable; ?>';
    
    评论

报告相同问题?