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';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度