【问题标题】:Jquery Problem With Changing Element Attribute In Internet Explorer在 Internet Explorer 中更改元素属性的 Jquery 问题
【发布时间】:2011-04-22 16:30:37
【问题描述】:

我正在使用 Jquery 根据用户输入创建动态链接。我有一组元素 ajax 加载的 div 看起来像这样

<div class="mxcell">
<input type="text" size="40" class="input_name" value="">
<a href="#" target="_blank" class="dyn_link">
<img src="http://127.0.0.1/images/arrow_right.gif">
</a>
</div>

现在我在 Jquery 中编写

$(function(){
$("#right").delegate(".input_name", "change", function(){
var dyn_link = $(this).val()
$(this).parent().find("a").attr("href", "http://www.example.com/"+ dyn_link +".html");
});
});

这在 Chrome/Firefox 中运行良好,但在 Internet Explorer 中则不行。

有什么想法吗?

IE 调试器指向 Jquery 第 69 行字符 15。不知道进一步调查。

更新:

我通过使用 focusOut() 而不是 change() 解决了上述问题

但我仍然不确定是否有更好的解决方案

【问题讨论】:

  • 嗯,在更改 inputfeld 中的值时,会创建一个动态链接,例如 href = 'example.com/apples.html'。在 IE 中,这仍然是 href="#"

标签: internet-explorer jquery-selectors


【解决方案1】:

http://jsfiddle.net/pNZTe/

我会 keyup 而不是 focusOut,并且我清理了你的 href 转换器:

$("#right").delegate(".input_name", "keyup", function() {
    var $this = $(this);
    var dyn_link = $this.val();
    $this.next("a").attr("href","http://www.example.com/" + dyn_link + ".html");
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多