IE6中使用val()的jquery问题 [英] jquery-problem using val() in IE6

查看:83
本文介绍了IE6中使用val()的jquery问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jquery来获取textarea的值以进行更新,如以下代码中所述:

I'm trying to get a textarea's value to update using jquery as outlined in the below code:

<button type="button" onclick="setLine();">Set</button>
<button type="button" onclick="showLine();">fire!</button><p></p>
    <textarea id="hello">

    </textarea>
    <script type="text/javascript">
            $('#hello').val("hi there");
        </script>
    <script type="text/javascript">
        function showLine()
        {
            alert($('#hello').val());
        }
        function setLine()
        {
            $('#hello').val('foo');
        }
    </script>

此代码在IE6以外的所有主流浏览器中均能正常工作.

This code works fine in all major browsers except IE6.

在IE6中,textarea不会随着按钮单击而更新,并且警报会给出一个空白/空字符串.但是,在其他浏览器中,单击设置"会将其更改为"foo",然后将其显示在警报框中.

In Ie6 the textarea will not update with the buttonclick and the alert gives a blank/null string. However in other browsers, clicking "set" changes it to "foo" which is then shown in the alert box.

有人知道为什么这是特定于此浏览器的,还是代码可能有什么问题?我对.val()

Does anyone know why this is specific to this browser, or what may be wrong with the code? I have my suspicions about the .val()

任何帮助将不胜感激.

推荐答案

我认为您必须使用.html()而不是.val()...试着说发生了什么事?

I think that you must use .html() instead of .val() ... Try and say what is happened?

这篇关于IE6中使用val()的jquery问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆