我有一个图像按钮,我试图切换。但是,刷新时只切换一次。当我点击图片时,它应该改变到第二张图片,并在下一次点击时,改回到原始图片。通过此代码,我可以从第一张图片开始查看第二张图片,但是当我再次点击时,我无法获取原始图片。有人能指出我要去哪里吗?这是整个剧本,我现在用图像切换按钮只能工作一次
HTML &的jQuery -
<a href='#'>
<input type="image" src="/images/pulpit.jpg" id="btn-true" />
</a>
<script type="text/javascript">
$('#btn-true').click(function() {
if ($(this).prop("src", "/images/pulpit.jpg"))
$(this).prop("src", "smiley.gif");
else if ($(this).prop("src", "smiley.gif"))
$(this).prop("src", "/images/pulpit.jpg");
});
</script>
你无法使用.toggle(function .........? –
上面这段代码在w3schools编辑器中工作正常,但是当我在.net mvc 4 web应用程序中使用相同的代码时, 。任何原因,我可能会错过什么? – TechnoBlahble