所以我显示基于选择复选框的图形,并遇到一个小问题。获取所有的ONE属性的实例,而不是只有一个
我目前正在循环并选择第一个图表,即使选中全选复选框时也是如此 - 这意味着我得到了许多相同的第一个图形而不是十个独特的图形。
正如您将在下面的代码中看到的,我用的是以前的行注释掉:完美在Firefox
//var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value;
只能 - 它会显示所有图表正确等,但不工作在Chrome/IE中,由于它尝试访问元素的方式。
我与这两条线取代了它:
$el = $('#counterTreeviewUL'+idTreeview).first();
var fnInstance = $el.find("input").attr("onclick");
我有原因的一切取而代之的是在所有三个浏览器功能(在IE或Chrome没有错误了)这两条线,然而的只有图中显示的是第一个找到的 - 如果选择了三个元素,那么将显示第一个图的3个版本,而不是3个独特的图。
完整的代码的下方,什么样的元素包含console.logs是低于:元素
for (var i=0;i<$('#counterTreeviewUL'+idTreeview)[0].children.length;i++)
{
if (!$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked)
{
$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].checked=true;
//var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value;
$el = $('#counterTreeviewUL'+idTreeview).first();
var fnInstance = $el.find("input").attr("onclick");
fnInstance=fnInstance.substr(15).substr(0,fnInstance.length-2);
var flagsInstance=fnInstance.split(new RegExp(","));
var graph = {
id: seqId,
entityName: flags[6].substr(1).substr(0, flags[6].length - 2),
entity: flags[5].substr(1).substr(0, flags[5].length - 2),
idCounter: flags[4],
counterName: flags[3].substr(1).substr(0, flags[3].length - 2),
ivmanager: flags[7].substr(1).substr(0, flags[7].length - 2),
chart: null,
pointsToShowX: null,
borneInf: null,
unite: "",
idInstance: flagsInstance[2].substr(1).substr(0, flagsInstance[2].length - 2),
instanceName: flagsInstance[3].substr(1).substr(0, flagsInstance[3].length - 2),
listPdsNull: new Array(),
countInstance: idTreeview + "_" + i,
countGraph: -1
};
seqId++;
graphs[graphsLastId]=graph;
graphsLastId++;
}
}
Console.logs:
任何因为我花了几个小时试图解决(另一个以前雇员的)代码,所以帮助会很大。
我基本上只需要这一行的浏览器的版本 -
var fnInstance=$('#counterTreeviewUL'+idTreeview)[0].children[i].children[0].attributes[1].value;
您似乎仍然混合使用jQuery和纯DOM方法。 – Bergi
@Bergi这不是我的代码,我对你为什么这样做是困惑的。我会去改变所有的东西给JQuery,但现在这是唯一的'错误'我已经离开和截止日期的调用。 。只是不知道如何以IE和Chrome接受的方式复制注释行。 – lifetimes
对于开始,您可以使用$('#counterTreeviewUL'+ idTreeview +'input)缩短您的复选框选择器[类型= “复选框”]:检查')'。 – kayen