我不是一个Web开发人员,但试图修复代码中的东西,所以请原谅我,如果我忽略了一些东西。改变标签颜色的问题
我试图禁用复选框和标签时,另一个复选框被选中。
这是我的HTML看起来像:
<dl id="someParent">
<dd><input type="checkbox" name="checkbox1" id="checkbox1"/>
<label for="checkbox1" data-localize="someText.name1" class="checkbox1"> </label>
</dd><dd>
<input type="checkbox" name="checkbox2" id="checkbox2"/>
<label for="checkbox2" data-localize="someText.name2" class="checkbox2"> </label>
</dd><div class="clear"></div></dl>
JS:
$('#checkbox1').click(function() {
if($("#checkbox1").is(':checked')){
$('#checkbox2').attr("disabled", true);
$('label[data-localize="someText.name2"]').css("color", "red"); //This doesn't work
} else {
$('#checkbox2').removeAttr('disabled');
//Code to change label color. How, to access data-localize="someText.name2"? Where someText.name2 is defined in a json file as string, someText.name2: "This will be printed as label 1"
}
});
$('#checkbox2').click(function() {
if($("#checkbox2").is(':checked')){
$('#checkbox1').attr('disabled', true);
//Code to change label color. How, to access data-localize="someText.name1"? Where someText.name1 is defined in a json file as string, someText.name1: "This will be printed as label 2"
} else {
$('#checkbox1').removeAttr('disabled');
$('label[data-localize="someText.name1"]').css("color", "black"); //This doesn't work
}
});
//My issue is I can not access and hence change color of "someText.name1/2" which is a label/text next to the Checkbox1/2. Disabling the Checkbox is not an issue but greying out the label next to checkbox is an issue.
在原代码,程序代替someText.name1/2与来自JSON文件的映射字符串作为标签。
如果我在html中使用标签(如jsfiddle中使用Checkbox1,2作为标签所示),但是代码替换json文件中的数据本地化字符串时,我可以使其工作。 Checboxes本身工作正常,但标签不会改变颜色。
注:我无法更改代码的体系结构,因此我只能使用数据本地化。另外,这个问题不是关于改变标签的颜色,而是关于如何在使用数据本地化时访问和更改标签。
此外,Checkbox1和Checkbox2标签不是在原始代码中,而是生成动态替换someText.name1和someText.name2。
实施例:https://jsfiddle.net/w8s9rLme/34/
那么,'data-localize'属性意味着什么? –
EVen我不知道,但看在代码中,它看起来像映射到一个字符串:someText.name1:“一些映射字符串”在json文件中定义 – user353860
它不清楚你想实现什么。所以'data-localize'是动态的。哪个标签应该变色? '#someParent'下的所有其他标签? –