Javascript占位符在IE9中不起作用

时间:2015-04-09 06:23:56

标签: javascript internet-explorer

这是代码,

        $(document).ready(function() {

        // CREATE A "DIV" ELEMENT AND DESIGN IT USING JQUERY ".css()" CLASS.
        var container = $(document.createElement('div')).css({
            padding: '5px', margin: '0'});

        $(container).append('<input type=text class="input" id="tb1" placeholder="Email" />');
        $(container).append('<input type=text class="input" id="tb2" placeholder="Email" />');
        $(container).append('<input type=text class="input" id="tb3" placeholder="Email" />');
        $(container).append('<input type=text class="input" id="tb4" placeholder="Email" />');
        $('#main').before(container);   // ADD THE DIV ELEMENTS TO THE "main" CONTAINER.

        var iCnt = 4;

        $('#btAdd').click(function() {
            if (iCnt <= 19) {

                iCnt = iCnt + 1;

                // ADD TEXTBOX.

                $(container).append('<input type=text class="input" id=tb' + iCnt + '  placeholder="Email" />');

                $('#main').before(container);   // ADD BOTH THE DIV ELEMENTS TO THE "main" CONTAINER.
            }
            else {      // AFTER REACHING THE SPECIFIED LIMIT, DISABLE THE "ADD" BUTTON. (20 IS THE LIMIT WE HAVE SET)

                $(container).append('<label>Reached the limit</label>'); 
                $('#btAdd').attr('class', 'bt-disable'); 
                $('#btAdd').attr('disabled', 'disabled');

            }
        });
}

我在所有浏览器中测试,它在IE10和IE11中工作正常,但在IE9中没有占位符名称“email”。

我可以知道,如何解决这个问题,有人可以帮我吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

不幸的是,IE9不支持占位符这样的属性。但你可以使用jQuery来避免它。此链接可以帮助您:Placeholder in IE9