dt3674 2016-03-28 15:15
浏览 53
已采纳

Laravel使用javascript更改刀片文件中的图像

I am trying to use javascript to change an image in my blade file but am getting the following error. As a side note I have enabled HTML forms in laravel, and I am able to display images without javascript.

Fatal error: Class 'HTML' not found (View:/home/vagrant/Code/Laravel/resources/views/pages/progress.blade.php)

Below is my javascript code

<script>
window.onload = function() {
changeImageForSeniorLevel();

};

function changeImageForSeniorLevel() {
var level = '<?php echo $levelValue; ?>';

if (level == 3)
{
document.getElementById("image").src="{{ HTML::image('progress2/Icons/Calls_Icon.png', 'alt',array('width' => 150 )) }}";
}
}
</script>

Here is the code for the image I am trying to change, the code will display an image if I comment my javascript.

{{ HTML::image('progress2/Icons/Meetings_Icon.png', 'alt', array('id' => 'image', 'width' =>150)) }}
  • 写回答

1条回答 默认 最新

  • dongxi3911 2016-03-28 15:28
    关注

    HTML::image is a Laravel class / method that is parsed in PHP (which is hosted on your server). You cannot parse it using a browser / HTML. The browser does not know what HTML::image means. In your case, you just want to change the attributes of an image already drawn on your document.

    You can use the following to achieve what you are looking for:

    if(level == 3){
        var myImage = document.getElementById("image");
        myImage.src = 'progress2/Icons/Calls_Icon.png';
        myImage.alt = 'alt';
        myImage.style.width = '150px';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!