Firefox的jQuery问题:$('#element_id').html()无法正常工作 [英] JQuery issue with firefox: $('#element_id').html() not working

查看:51
本文介绍了Firefox的jQuery问题:$('#element_id').html()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< div id ="element_id"> hellow world</div>

var value = $('#element_id').html() 

有时(但不总是)返回"hello world" . val()始终有效,但 html()无效(仅在firefox中有效(始终在Chrome中有效)).有什么想法吗?

returns the "hello world" sometimes, but not always. val() always works, but not html() This only happens in firefox (always works in Chrome). Any ideas?

编辑仍然没有找出问题所在,但是一旦发现问题,我将发布结论!感谢您的答复.

EDIT Still haven't figured out the problem yet, but I will post the conclusion once I have found it! Thanks for the responses.

推荐答案

完整的不变代码供您尝试:

The complete unaltered code for you to try:

<!doctype html>
<html lang="pt-br">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            p {color:#4f4}
            code {color:#999;font-family:monospace;font-size:14px}
        </style>
        <script type="text/javascript" src="libraries/jquery-1.4.4.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                function showhtml(n) {
                    //1 for html 0 for text
                    if(n == 1) {
                        var eid = $('div.eid').html();
                        alert(eid);
                        $('code.status').html(eid);
                    } else if(n == 0 || n == null) {
                        var eid = $('div.eid').text();
                        alert(eid);
                        $('code.status').text(eid);
                    }
                }
                showhtml();
            });
        </script>
        <title>jQuery html() text()</title>
    </head>
    <body>
        <div class="eid">
            <p>1 ajfdlk jaldkfjdksljfkldjlfkjal;fd</p>
            <em>2 ajd;fjal;kdjf</em>
        </div>
        <br />
        <hr />
        <code class="status"></code>
    </body>
</html>

这篇关于Firefox的jQuery问题:$('#element_id').html()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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