在IE8中使用jQuery更改href属性

时间:2013-01-09 10:04:22

标签: jquery internet-explorer internet-explorer-8 href

在我正在处理的项目中,我需要动态更改href - 标记的<a>值。

所以我正在使用这样的东西:

var link = '/foo' // Some calculation to determine the correct link.
$('div.button-export a').attr('href', link);

除了 - 当然 - IE8之外,它适用于所有浏览器。 它只是忽略了.attr()方法,或者有一个错误或什么。我需要为IE8修复此问题,我需要快速修复它。

你知道IE8到底发生了什么,以及如何解决这个问题?

更新:完整代码

var exportLink = jQuery('div.button-export a').first();

// TODO: SHOULD DO THIS WITH THE getExtent() METHOD
var data = {
    box:[
        GRD.mapController.map.extent.xmin,
        GRD.mapController.map.extent.ymin,
        GRD.mapController.map.extent.xmax,
        GRD.mapController.map.extent.ymax
    ],
    sr:GRD.mapController.map.extent.spatialReference.wkid,
    layer:GRD.mapController.shownCountryLayer,
    layerNoRegions:GRD.mapController.shownCountryLayerNoRegions,
    urlRegions:encodeURIComponent(GRD.mapController.config.country),
    urlCountry:encodeURIComponent(GRD.mapController.config.countryNoRegions)
};

exportLink.prop('href', Routing.generate('api_export_report_pdf', { "id":CI.report.cid, "data":JSON.stringify(data) })).show();

更新 对困惑感到抱歉。当然我使用了正确的选择器。我只是稍微改了一下。仍然无效。

2 个答案:

答案 0 :(得分:0)

我想这个:

$('button.export a').attr('href', link);

应该是这样的:

$('div.button-export a').attr('href', link);

答案 1 :(得分:0)

最后我能够发现问题。没有真正的错误,IE 8的开发工具中解析的DOM-Tree只是没有更新,所以我不得不手动刷新它......

该链接也无法正常工作,因为内部有一个按钮,IE8似乎在<button> - 标记内的<a>出现问题。

抱歉所有的困惑。