【问题标题】:change the href property with jQuery in IE8在 IE8 中使用 jQuery 更改 href 属性
【发布时间】:2013-01-09 10:04:22
【问题描述】:

在我正在进行的项目中,我需要动态更改 <a>-Tag 的 href 值。

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

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();

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

【问题讨论】:

  • 你试过javascript的版本吗? $('button.export a')[0].setAttribute('href', link);
  • 尝试使用prop: $('button.export a').prop('href', link);,假设你的jQuery版本> 1.6
  • 在按钮内有一个锚点听起来像是一种可能会混淆某些东西的东西......
  • 请发布您的完整代码。
  • 这个$('button.export a').attr('href', link);和这个jQuery('div.button-export a').first();有两个不同的classes,一个使用button.export(按钮的类名为export),另一个使用div.button-export(div的类名为button-export )。

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


【解决方案1】:

我认为是这样的:

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

应该是这样的:

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

【讨论】:

    【解决方案2】:

    最后我能够检测到问题。没有真正的bug,IE 8的开发者工具中解析出来的DOM-Tree没有更新,只好手动刷新...

    该链接也不起作用,因为里面有一个按钮,而 IE8 似乎在 <a>-Tag 内的 <button> 存在问题。

    抱歉给大家带来了困惑。

    【讨论】:

      猜你喜欢
      • 2014-07-21
      • 2018-10-30
      • 1970-01-01
      • 2010-09-15
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多