0
現在我正在開發使用Laravel 5.0的電子商務購物網站,這對於我的fyp來說,還有很長的路要走。Laravel Javascript Image Swap Dropdown List
而且,我做產品展示頁面
這是我的控制器:
public function getView($id)
{
return view('store.show')->with('products', Product::find($id))->with('categories',Category::all())->with('db',Product::all())->with('options', Gambar::where('product_id','=',$id)->lists('name', 'img'));
}
正如你可以看到,在該行的末尾有代碼列表(「姓名」,「IMG」 )
它會列出列名和影像值轉換爲一個列表
一切都完美的作品接受,我需要馬可以通過選擇圖像更改下拉列表。
看待我的下拉列表中imageswap代碼:
<div class="form-group">
{!! Form::open(array('url' => 'foo/bar')) !!}
{!! Form::label('Link Category') !!}<br />
{!! Form::select('product_id',(['0' => 'Select an Option'] + $options),null,['class' => 'form-control', 'id' => 'dlist', 'onChange' => 'swapImage()']) !!}
{!! Form::close() !!}
<script type="text/javascript">
function swapImage(){
var image = document.getElementById("imageToSwap");
var dropd = document.getElementById("dlist");
image.src = dropd.value;
};
</script>
</div>
而且這個代碼在圖像上會出現選擇(產品 - >圖像是主圖像的基礎,而不是從下拉列表種子:
<img id="imageToSwap" src="{{asset($products->image)}}" />
在控制器作品列表的流量,但它給這個在查看源鉻:
<img id="imageToSwap" src="img/upload/20-3-291-image-1.jpg" />
所以圖像不會出現在頁面上,它應該出現這樣的:
<img id="imageToSwap" src="localhost:8000/img/upload/20-3-291-image-1.jpg" />
的問題是,如何返回「IMG」與laravel資產{{資產()}},所以圖像可以完美顯示?
error apply when image.src =「{{asset()}} /」+ dropd.value; helpers.php中的ErrorException第81行: 缺少資產()的參數1,在第100行中調用並在C:\ xampp \ htdocs \ myweb2 \ storage \ framework \ views \ a3ea3da5b741ea4eca39686d1e2d05b0中調用並且已定義(View:C:\ xampp \ htdocs \ myweb2 \ resources \ views \ store \ show.blade.php) –
嘗試使用'asset('')' – oliverpool
thanksss bro,它的工作原理 –