现场活动后 jQuery this.text 在 IE 中不起作用

发布于 2024-10-10 05:12:59 字数 725 浏览 0 评论 0原文

我目前正在尝试使用一些 jQuery 函数更新我的网站。与 Web 开发一样,IE 一直是一种痛苦。

我有一个如下所示的自动建议列表:

<div id="suggestionBox">
    <ul>
        <li>
            <a class="entry" style="display:block;" href="#">somesuggestion</a>
        </li>
        ...
    </ul
</div>

当然,建议是从服务器获得的,因此每次输入字段更改时我都会使用 load() 函数。这一切都很好。 问题是,我希望在单击建议时完成输入字段。 我使用以下代码:

$(".entry").live('click', function() {
    $("#" + $("#suggestionBox").data('input')).val(this.text);
    //and some more stuff
});

当输入字段获得焦点时,将设置 suggestBox 的数据字段。

它在 Chrome 和 FireFox 中工作得很好,但在 IE 中却不行。 上面代码中的 this.text 返回未定义。

我不知道为什么这不适用于 IE。有人可以帮助我吗?

谢谢。

I am currently trying to update my website with some jQuery functions. As allways with web development IE is being a pain.

I have an autosuggestion list that looks like this:

<div id="suggestionBox">
    <ul>
        <li>
            <a class="entry" style="display:block;" href="#">somesuggestion</a>
        </li>
        ...
    </ul
</div>

Of course, the suggestions are gained from a server, so I use a load() function every time the input field is changed. This works all fine.
The problem is, I want the input field to be completed when a suggestion is clicked.
I use the following code for that:

$(".entry").live('click', function() {
    $("#" + $("#suggestionBox").data('input')).val(this.text);
    //and some more stuff
});

The data field for the suggestionBox is set when the input field gets focus.

It works perfectly fine in Chrome, and FireFox but not in IE.
this.text in the above code returns undefined.

I have no clue why this shouldn't work for IE. Can anyone help me?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2024-10-17 05:12:59

为什么不使用 jQuery?

$(this).text()

a 元素没有IE 中的 text 属性

Why don't you use jQuery?

$(this).text()

An a element has no text property in IE.

┼── 2024-10-17 05:12:59

您需要使用 jQuery 的 text() 函数,而不是属性,因为底层 DOM 属性是特定于浏览器的:

$("#" + $("#suggestionBox").data('input')).val($(this).text());  

You need to use jQuery's text() function, not property, since the underlying DOM property is browser-specific:

$("#" + $("#suggestionBox").data('input')).val($(this).text());  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文