【问题标题】:Href problem with IE and Edge that does not redirect不重定向的 IE 和 Edge 的 Href 问题
【发布时间】:2019-09-18 06:33:30
【问题描述】:

我遇到了一个在 Edge 或 IE 上不起作用但在其他浏览器上完美运行的 href 问题。

为了解释操作,我有一个带有 3 个下拉列表的表单。用户必须从每个列表中选择一个值来激活 a href。 href 的内容在 jQuery 中根据列表中的选择进行动态化。动态化工作正常,但一旦链接激活,当我点击它时不会发生。

默认情况下,我的链接创建如下:

<a href="#" id="buttonSearchPro" disabled="disabled" style="cursor: default;">
    <input role="button" class="btn btnAction" value="Validate" />
</a>

一旦用户在 3 个列表中选择了一个值,我将调用以下 jQuery 方法:

var typeProSearch = $('#typeProSearch').val();
var typeSearch = $('#typeSearch').val();
var choiceDepartment = $('#choiceDepartment').val();
var hrefListPro = "/ProfessionalList/Index_ProfessionalList?typeProSearch=" +
    typeProSearch +
    "&typeSearch=" +
    typeSearch +
    "&department=" +
    choiceDepartment +
    "&townName=all";
$('#buttonSearchPro').attr('href', hrefListPro);
$('#buttonSearchPro').prop('disabled', false);

之后,如果我检查该项目,我的 URL 在 href 中,但是当我单击链接时,什么也没有发生。我们是否应该在 Edge 下添加一些要考虑到 href 的内容?

【问题讨论】:

  • 您可能需要考虑使用 encodeURIComponent 包装来自文本框的值,以确保它们在 URL 中有效。
  • 渲染的锚标签是什么样的?比如,如果你检查元素并获取标签的完整 HTML?
  • 我发现了问题。为了让按钮更接近视觉效果,我们在标签 a 中放置了一个输入。但是,edge 不支持在 a 中输入。我们删除了输入,一切正常。

标签: jquery internet-explorer .net-core microsoft-edge razor-pages


【解决方案1】:

尝试使用以下方法解决此问题:

方法一:为输入元素添加类型属性(type="button")。请修改您的代码如下:

<a href="#" id="buttonSearchPro" disabled="disabled" style="cursor: default;">
    <input role="button" type="button" class="btn btnAction" value="Validate" />
</a>

方法2:使用window.location.href 重定向到页面。代码如下:

var typeProSearch = $('#typeProSearch').val();
var typeSearch = $('#typeSearch').val();
var choiceDepartment = $('#choiceDepartment').val();
var hrefListPro = "/ProfessionalList/Index_ProfessionalList?typeProSearch=" +
    typeProSearch +
    "&typeSearch=" +
    typeSearch +
    "&department=" +
    choiceDepartment +
    "&townName=all";
$('#buttonSearchPro').attr('href', hrefListPro);
$('#buttonSearchPro').prop('disabled', false);
//redirect to the new page.
window.location.href = hrefListPro;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-30
    • 2018-01-09
    • 2012-12-31
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    相关资源
    最近更新 更多