在jQuery中循环遍历图表类型的元素

时间:2012-09-27 16:46:10

标签: jquery

如果它包含图表,我想循环遍历“.dxpc-content img”类型的所有元素...然后我想通过检索它的属性“id”来调用图表上的PerformCallback方法,其中包含以下内容:

我这样做是这样的:

$('.dxpc-content img').each(
    function () {
        if ($(this).attr("id").attr("id")) {
            alert("contains chart");

            if ($(this) && $(this).attr('id').attr('id') && window[$(this).attr('id').attr('id')].PerformCallback) {
                window[$(this).attr('id').attr('id')].PerformCallback("stat" + "," + brokerStats);
            }
        }

    }

如果我检查Chrome开发工具中的元素,它看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:1)

您的图表包含ids starting with barChart ...可以在附加的图片中看到,因此您需要找到元素having ids containing barChart

$('.dxpc-content img').each(
    function () {
        if ($(this).attr("id").indexOf('barChart') != -1) {
            alert("contains chart");

            if ($(this) && $(this).attr('id').attr('id') && window[$(this).attr('id').attr('id')].PerformCallback) {
                window[$(this).attr('id').attr('id')].PerformCallback("stat" + "," + brokerStats);
            }
        }

    }