相关疑难解决方法(0)

如何在点击时更改图像和alt属性?

我希望使用JQuery而不是普通的JavaScript更改几个图像,并同时更改图像alt属性以便访问.

它应该是容易的,因为我不打算对变化做一些特殊的影响,但我仍然没有找到任何关于它的东西.

这是我使用JS的方式(不更改alt属性):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Change Image using Javascript</title>
<script type="text/javascript">
   function changeImg(image_id, image_folder){
   document.getElementById(image_id).src = image_folder;
}
</script>
</head>
<body>
<div align="center">

<img id="image1" src="images/nameofthesubfolder/originalimage1.jpg" alt="Original Image 1" />
<br />
  <label><input type="radio" name="radio_btn1" onclick="changeImg('image1', 'images/nameofthesubfolder/image1.jpg')"/>Image 1</label>
  <label><input type="radio" name="radio_btn1" onclick="changeImg('image1', 'images/nameofthesubfolder/image2.gif');"/>Image 2</label>
  <label><input type="radio" name="radio_btn1" onclick="changeImg('image1', 'images/nameofthesubfolder/image3.png');"/>Image 3</label>
  <label><input type="radio" name="radio_btn1" onclick="changeImg('image1', 'images/nameofthesubfolder/image4.jpeg');"/>Image 4</label>
<br />
<br />
<img id="image2" src="images/nameofthesubfolder/originalimage2.jpg" alt="Original Image 2" />
<br />
  <label><input type="radio" …
Run Code Online (Sandbox Code Playgroud)

jquery accessibility image onclick alt-attribute

5
推荐指数
1
解决办法
5万
查看次数

标签 统计

accessibility ×1

alt-attribute ×1

image ×1

jquery ×1

onclick ×1