当用户单击按钮时,我需要将收集项目值与刀片模板中的文本进行比较。
类似这样的东西
@foreach notes as note
@if $note->number == <input id="number" name="number">
<h2>$note->contente</h2>
@endif
@endforeach
请问如何进行这种比较?
答案 0 :(得分:1)
这必须用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>
我希望这对您有帮助