[英]How to get value of input attribute and background color of nearby div element?
I have some div with id = "ctl00_ContentPlace_dvColorsArea"
inside that div I have inputs of type text. 我在该div中有一些
id = "ctl00_ContentPlace_dvColorsArea"
div,我有文本类型的输入。
Under every input I have div element that contains another child div. 在每个输入下,我都有一个div元素,其中包含另一个子div。
Here is example: 这是示例:
<div id="ctl00_ContentPlace_dvColorsArea">
<input name="ctl00$ContentPlace$ctl00" type="text" legendlabel="Zone: AGR" style="display: none;">
<div class="sp-replacer sp-light sp-active">
<div class="sp-preview">
<div class="sp-preview-inner" style="background-color: rgb(235, 217, 190,0.12);"></div>
</div>
</div>
<input name="ctl00$ContentPlace$ctl00" type="text" legendlabel="Zone: ZGY" style="display: none;">
<div class="sp-replacer sp-light sp-active">
<div class="sp-preview">
<div class="sp-preview-inner" style="background-color: rgb(85, 45, 50);"></div>
</div>
</div>
</div>
At some point I need to get from every input attribute with name legendlabel his value and background-color of the child div under the input element. 在某个时候,我需要从每个带有Legendleglabel名称的输入属性中获取其值和输入元素下子div的背景颜色。
For example according to HTML above : 例如,根据上面的HTML:
[{
legendlabel:"Zone: AGR"
backgroundColor:rgb(235, 217, 190,0.12)
},
{
legendlabel="Zone: ZGY"
backgroundColor:rgb(85, 45, 50)
}]
I know that using this row $("#ctl00_ContentPlace_dvColorsArea :input").attr(legendlabel);
我知道使用此行
$("#ctl00_ContentPlace_dvColorsArea :input").attr(legendlabel);
I can get attribute value of every input. 我可以获得每个输入的属性值。 But I need to get also a childs div background color.
但是我还需要获取childs div背景颜色。
Any idea how can I get from every input attribute with name legendlabel his value and background-color of the child div under the input element? 知道如何从每个带有legendlabel标签的输入属性中获取其值和输入元素下子div的背景颜色吗?
you can use this code 您可以使用此代码
$('#ctl00_ContentPlace_dvColorsArea :input').each(function (index, value) {
var label = $(value).attr("legendlabel");
var color = $(value).next().find(".sp-preview-inner").css("background-color");
console.log(label);
console.log(color);
});
check this 检查这个
var ele = document.getElementById('ctl00_ContentPlace_dvColorsArea').getElementsByTagName("input"); var output = [...ele].map((val, i)=> { return { legendlabel: val.getAttribute("legendlabel"), backgroundColor: $(val).next().find('.sp-preview-inner').css('background-color') } }); console.log(output);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="ctl00_ContentPlace_dvColorsArea"> <input name="ctl00$ContentPlace$ctl00" type="text" legendlabel="Zone: AGR" style="display: none;"> <div class="sp-replacer sp-light sp-active"> <div class="sp-preview"> <div class="sp-preview-inner" style="background-color: rgb(235, 217, 190,0.12);"></div> </div> </div> <input name="ctl00$ContentPlace$ctl00" type="text" legendlabel="Zone: ZGY" style="display: none;"> <div class="sp-replacer sp-light sp-active"> <div class="sp-preview"> <div class="sp-preview-inner" style="background-color: rgb(85, 45, 50);"></div> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.