![](/img/trans.png)
[英]Laravel How to compare an input array collection with the array collection selected from the database
[英]Laravel! How to compare a collection value with a <input> text?
當用戶單擊按鈕時,我需要將集合項值與刀片模板中的文本進行比較。
像這樣的東西
@foreach notes as note
@if $note->number == <input id="number" name="number">
<h2>$note->contente</h2>
@endif
@endforeach
請問我該如何進行這種比較?
這必須通過 Javascript 完成,Blade 在您的 Javascript 加載或輸入更改之前輸出 HTML 方式
這是一個例子(不要復制粘貼)
@foreach($notes as $note)
<h2 hidden>{{ $note->name }}</h2>
<input id="number" name="number"><br>
@endforeach
<button onclick="showCorrectNames()">Check</button>
<script>
function showCorrectNames() {
var inputs = document.getElementsByTagName("input");
for (let input of inputs) {
if (input.value === input.previousElementSibling.innerText) {
input.previousElementSibling.hidden = false;
}
}
}
</script>
function showCorrectNames() { var inputs = document.getElementsByTagName("input"); for (let input of inputs) { if (input.value === input.previousElementSibling.innerText) { input.previousElementSibling.hidden = false; } } }
<h2 hidden>Cecelia Denesik Jr.</h2> <input id="number" name="number"><br> <h2 hidden>Cristian McCullough</h2> <input id="number" name="number"><br> <h2 hidden>Forest Pollich</h2> <input id="number" name="number"><br> <h2 hidden>Mckenna Jacobson</h2> <input id="number" name="number"><br> <h2 hidden>Rudolph Luettgen MD</h2> <input id="number" name="number"><br> <h2 hidden>Mazie Shields III</h2> <input id="number" name="number"><br> <h2 hidden>Mr. Arlo Hudson Sr.</h2> <input id="number" name="number"><br> <h2 hidden>Joanie Rogahn</h2> <input id="number" name="number"><br> <h2 hidden>Stephan Feil</h2> <input id="number" name="number"><br> <h2 hidden>Isadore Schultz</h2> <input id="number" name="number"><br> <button onclick="showCorrectNames()">Check</button>
我希望這有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.