简体   繁体   中英

How to call a javascript function from if statement of Laravel?

I want to call a javascript function from if statement of Laravel Blade. Is it possible?

@if(compareParent())
   Print Something
@endif

Javascript:

function compareParent() {
    $(".CategoryIDForModal").click(function () {
    var id = $(this).data(id);
    var parent_id = $('.subcategoryPID').text();

     console.log(id.id + " Parent: " + parent_id);
     if(id==parent_id)
    return true;
     else
    return false;
     })
}

No, the @if blade statement is evaluated server side and from a php processor, javascript is evaluated client side .

So you need to have a compareParent() function defined in php if you don't want to raise an error.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM