Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改图像';通过使用标题名使用Javascript创建s href?_Javascript_Css_Href - Fatal编程技术网

如何更改图像';通过使用标题名使用Javascript创建s href?

如何更改图像';通过使用标题名使用Javascript创建s href?,javascript,css,href,Javascript,Css,Href,在本幻灯片中,大约有50幅图像。我使用的平台与wordpress类似,不允许我更改image href。这些图像具有相同的类名。是否可以使用标题名(每个图像的标题名都是唯一的)并更改一些图像的href <div id="slideshow" class="vlt-d-slider" style="position: relative; overflow: hidden; width: 928px; height: 522px;"> <div class="slide"

在本幻灯片中,大约有50幅图像。我使用的平台与wordpress类似,不允许我更改image href。这些图像具有相同的类名。是否可以使用标题名(每个图像的标题名都是唯一的)并更改一些图像的href

<div id="slideshow" class="vlt-d-slider" style="position: relative; overflow: hidden; width: 928px; height: 522px;">
    <div class="slide" data-vltcaption="0" data-brand="none" data-topic="INST" data-url="_0.jpg" style="position: absolute; left: 0px; visibility: visible; z-index: 3; line-height: 520px; height: 522px;">
<a class="slide-lightbox" rel="vlt-slideshow" href="m_0.jpg" title="Pfusc number photo 1" target="_blank">
<img class="slide-img" src="_0.jpg" alt="Pfusc number photo 1">
</a>
</div>
      <div class="slide" data-vltcaption="1" data-brand="none" data-topic="INST" data-url="0.jpg" style="position: absolute; left: 0px; visibility: hidden; z-index: 1; line-height: 520px; display: block; height: 522px;">
<a class="slide-lightbox" rel="vlt-slideshow" href="f_0.jpg" title="Pfusc number photo 2" target="_blank">
<img class="slide-img" src="0.jpg" alt="Pfusc number photo 2">
</a>
</div>
      <div class="slide" ....
</div>
    </div>


首先,图像没有
href
,它们有
src

第二,我想你说的“标题名”是指
alt

在这种情况下,
document.querySelector('[alt=“thetitle”]').src='thenewsrc'


如果您想通过链接的标题找到它,您必须执行
document.querySelector('a[title=“the title”]>img')。src='the new src'

首先,图像没有
href
,它们有
src

第二,我想你说的“标题名”是指
alt

在这种情况下,
document.querySelector('[alt=“thetitle”]').src='thenewsrc'


如果您想通过链接的标题找到它,您必须执行
document.querySelector('a[title=“the title”]>img')。src='the new src'

对于start,我不确定您是否要更改
标记
img标记
属性,但我假定它是
标记
,因为您提到了
href
。是的。您可以这样做:

$("a[title='yourTitle']").attr('href', 'https://www.google.com/');
如果您想要图像:

$('img[alt="Your Alt"]').attr('src', 'image.jpg');

首先,我不确定您是否要更改
a标记
img标记
属性,但由于您提到
href
,我假定它是
a标记
。是的。您可以这样做:

$("a[title='yourTitle']").attr('href', 'https://www.google.com/');
如果您想要图像:

$('img[alt="Your Alt"]').attr('src', 'image.jpg');

你是指按标题显示的alt属性吗?你是指按标题显示的alt属性吗?你是说,jQuery是可用的,甚至没有提到jQuery。你是对的,如果OP需要,我会调整代码。你是说,jQuery是可用的,甚至不提jQuery。你是对的,如果OP需要香草,我会调整代码。你可以使用
('a[title=“the title”]>img')
并避免使用第二个查询选择器来简化代码。谢谢,@funcoding编辑了它!哎呀,你应该马上看一看这些基础知识;-)您可以使用
('a[title=“the title”]>img')
并避免使用第二个查询选择器来简化它。谢谢,@funcoding编辑了它!哎呀,你应该马上看一看这些基础知识;-)