jQuery追加不在IE8中工作 [英] jQuery append not working in IE8

查看:94
本文介绍了jQuery追加不在IE8中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $('#buttonadd').click(function(){
            if ($counter < 10)
            {
                $counter++;
                $countonlyadd++;
                $('#buttondiv').append('<tr><td><select class="combo" name="combo'+$counter+'" style="width: 60px;" size="1"><option>UND</option><option>OHNE</option><option>ODER</option></select></td><td><input type="text" name="textbox'+$counter+'" class="textbox" value="" /><a id="removetxt" class="removetxt" style="text-decoration: none;line-height: 3;" href="#">&nbsp;[X]</a></td></tr>');
            }else{
            }
            $('#send_count').val($countonlyadd);
        });

我的代码在Internet Explorer中不起作用,我不知道为什么。所有其他浏览器都可以,但IE不是。他甚至没有添加1个文本框。

My code is not working in Internet Explorer, and i dont know why. All other browsers are ok but IE is not. He is not adding even 1 textbox.

推荐答案

问题是IE兼容模式。这适用于IE9 http://jsfiddle.net/NP9pG/3/ 和Firefox,但是当你切换到IE兼容模式它不起作用。

ya the problem is IE compatibility mode. This works fine in IE9 http://jsfiddle.net/NP9pG/3/ and firefox but when you switch to IE compatibility mode it doesn't work.

<div id="buttondiv">  </div>
<div id="send_count"></div>
<input type="button" id="buttonadd" value="add" />

但这 http://jsfiddle.net/NP9pG/4/ 将在IE兼容模式下正常工作

but this http://jsfiddle.net/NP9pG/4/ will work fine tho in IE compatibility mode

<table id="buttondiv">  </table>
<div id="send_count"></div>
<input type="button" id="buttonadd" value="add" />

你的问题是你的html标记建议进行以下更改

ya the problem is your html mark-up as suggested make the following change

<div id="buttondiv">
  <table id="tableData"></table>
</div>

而不是将项目附加到而不是 div 元素

rather append items to table instead of div element

因此js代码:

$('#tableData').append('<tr><td><select class="combo" name="combo'+$counter+'"  style="width: 60px;"  size="1"><option>UND</option><option>OHNE</option><option>ODER</option></select></td><td><input  type="text" name="textbox'+$counter+'"  class="textbox" value="" /><a id="removetxt" class="removetxt"  style="text-decoration: none;line-height: 3;"  href="#">&nbsp;[X]</a></td></tr>');

希望有帮助

这篇关于jQuery追加不在IE8中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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