控制器代码,
public function postApprove($id)
{
$application = Move::where('id', '=', e($id))->first();
if($application)
{
$application->approved = 1-$application->approved;
$application->save();
return redirect()->route('driver');
}
}
这是jscript代码,
<script language="javascript">
function changeImage() {
if (document.getElementById("imgClickAndChange").src == "http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg")
{
document.getElementById("imgClickAndChange").src = "http://www.clker.com/cliparts/1/1/9/2/12065738771352376078Arnoud999_Right_or_wrong_5.svg.hi.png";
}
else
{
document.getElementById("imgClickAndChange").src = "http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg";
}
}
在视野中
<span><a href="{!! route('approve', ['id' => $user->id]) !!}"><img alt=""
src="http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg"
style="height: 85px; width: 80px" id="imgClickAndChange"
onclick="changeImage()" /></a></span>
此代码更改了dbvalue但刷新图像时获取默认图像。如何解决问题
答案 0 :(得分:0)
您可以通过将.src
事件附加到元素并将问题作为处理程序的代码分配给函数来切换.value
元素的<input type="image">
和click
<input
id="imgClickAndChange"
type="image"
src="http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg"
name="image"
value="123"
width="320"
height="280"/>
<script>
var input = document.getElementById("imgClickAndChange");
input.onclick = changeImage;
function changeImage() {
if (input.src == "http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg" && input.value === "123") {
input.src = "http://www.clker.com/cliparts/1/1/9/2/12065738771352376078Arnoud999_Right_or_wrong_5.svg.hi.png";
input.value = "456";
} else {
input.src = "http://school.glwh.org/wp-content/uploads/bigstock-vector-green-positive-checkmar-16955600.jpg";
input.value = "123";
}
console.log(input.src, input.value);
}
</script>
&#13;