从问题和演示中,
How to compare several td.text() in tr using jQuery
https://jsfiddle.net/lmgonzalves/cqa6m6va/1/
它展示了如何确定td元素中的重复项。
我的问题是如何在td中的选择元素中执行此操作:
<td style="max-width:160px" class="ellipsis">
<select class="select make-long-select fieldEditable ddSample" style="display:none;" name="sampleName">
<option value="SampleValue1">SampleValue1</option>
</select>
<span class="lblSample lblCurrentValue">SampleValue1</span>
</td>
<td style="max-width:160px" class="ellipsis">
<select class="select make-long-select fieldEditable ddSample" style="display:none;" name="sampleName">
<option value="SampleValue2">SampleValue2</option>
</select>
<span class="lblSample lblCurrentValue">SampleValue2</span>
</td>
<td style="max-width:160px" class="ellipsis">
<select class="select make-long-select fieldEditable ddSample" style="display:none;" name="sampleName">
<option value="SampleValue1">SampleValue1</option>
</select>
<span class="lblSample lblCurrentValue">SampleValue1</span>
</td>
<td style="max-width:160px" class="ellipsis">
<select class="select make-long-select fieldEditable ddSample" style="display:none;" name="sampleName">
<option value="SampleValue3">SampleValue3</option>
</select>
<span class="lblSample lblCurrentValue">SampleValue3</span>
</td>
我需要实现与此脚本的最后一个问题相同的行为。
我试过这种方法,但没有运气:
tds = $(this).find('td.ddSample');
tds.each(function(j, elem1){
tds.each(function(k, elem2){
if($(elem1)[0] != $(elem2)[0] && $(elem1).text() == $(elem2).text()){
$(elem1).addClass('cl');
}
});
});
注意:我只需要比较ddSample数据(假设我在tr中有其他数据)
答案 0 :(得分:0)
的javascript
var tds;
$('tr').each(function(i, item){
tds = $(this).find('td');
tds.each(function(j, elem1){
tds.each(function(k, elem2){
if($(elem1)[0] != $(elem2)[0] && $(elem1).find("select").html() == $(elem2).find("select").html()){
console.log($(elem1).find("select").html());
$(elem1).addClass('cl');
}
});
});
});
答案 1 :(得分:0)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Director : MonoBehaviour {
private GameObject mainMenu, options;
void Awake (){
mainMenu = GameObject.Find ("MainMenuCanvas");
options = GameObject.Find ("OptionCanvas");
}
void Start () {
mainMenu.SetActive (true);
options.SetActive (false);
}
void Update () {
//should i put If.else here?
/* like
if (button.clicked){
mainMenu.SetActive (false);
options.SetActive (true);*/
}
}
}
答案 2 :(得分:0)
点击此处 jsfiddle
使用了你提供的相同JQ,但不是在元素中添加一个类(PUT /_template/template_1
{
"template": "yourindex*",
"mappings": {
"my_type": {
"dynamic_templates": [
{your dynamic templates ...}
]
}
}
}
),而是将类添加到它的父元素(option
)中,然后在CSS中设置下一个{ {1}} select
检查上面的小提琴或下面的片段
span
color:red
var opt = $(".ddSample option")
opt.each(function(j, elem1){
opt.each(function(k, elem2){
if($(elem1)[0] != $(elem2)[0] && $(elem1).val() == $(elem2).val()){
$(elem1).parent(".ddSample").addClass('cl');
}
});
});