我想在選擇一個選項時獲取 $animal 的值,以便我可以按下按鈕并查看此選項的詳細資訊。
代碼
@foreach ($animais as $animal)
<option value="{{ $animal->id }}">{{ $animal->nome }}</option>
@endforeach
</select>
<a href="{{ route("animals.show", $animal) }}"><button type="submit">Ver</button></a>
uj5u.com熱心網友回復:
其中一個 HTML 頁面是用 PHP 撰寫的,該值是 DOM 中的一個節點,您可以通過 javascript 訪問它。
window.addEventListener('DOMContentLoaded', () => {
document.querySelector('select.example').addEventListener('change', e => {
console.log('value selected: ', e.target.value, 'from text', e.target.options[e.target.selectedIndex].text)
})
})
<select class='example'>
<option value='zebra'>animal</option>
<option value='carrot'>vegetable</option>
</select>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/365230.html
下一篇:從字串中獲取06號怎么做
