简体   繁体   English

动态添加的元素不在HTML表的TD中显示

[英]Dynamically Added Element Not showing in TD in HTML Table

I have this code : 我有这个代码:

var closeButton = $("<a class='close'/>")
                                    .button({
                                        icons: {
                                            primary: "ui-icon-close"
                                        },
                                        text: false
                                    })
                                    .removeClass("ui-corner-all")
                                    .addClass("ui-corner-right ui-combobox-toggle")
                                    .click(function () {
                                        if (invisibleElement != null)
                                            jQuery(invisibleElement).val("");
                                        //removing the close button with placaholder value
                                        jQuery(visibleElement).val("Select");
                                        jQuery(visibleElement).focus();
                                        jQuery(visibleElement).blur();
                                        var parentNode = $(this).parent();
                                        parentNode.find(this).remove();
                                        isCloseButton = false;
                                    });

And I am adding this button conditionally by this: 我通过以下条件添加此按钮:

$(visibleElement).parent().find(".showAll").after(closeButton);

This is not added by default. 默认情况下不添加。 This is added based on some input. 这是根据一些输入添加的。

These things are added within a td 这些东西在td中添加

<table border="0" width="100%" cellspacing='0' cellpadding='2'>
<tr>
    <td style="vertical-align:middle; text-align:left; width: 45%;">
                                <input type="text" id="theVisibleElement" value=""/>

    </td>
</tr>

But After adding the closeButton , I am not able to see the showAll element. 但是添加closeButton ,我看不到showAll元素。 Only the inputBox( visibleElement ) and the closeButton is visible. 仅inputBox( visibleElement )和closeButton可见。 Although, in the source code all three are there ie visibleElement(the input TextBox), showAll element and closeButton . 尽管在源代码中所有这三个都存在,即visibleElement(输入TextBox), showAll元素和closeButton Strangely the td is enough big but still all three are not shown up. 奇怪的是, td足够大,但仍未显示全部三个。 What to do? 该怎么办? Any suggestion? 有什么建议吗?

This is the jsfiddle: http://jsfiddle.net/8U6xq/1/ Though it's a bit messy. 这是jsfiddle: http : //jsfiddle.net/8U6xq/1/虽然有点混乱。

This is a CSS problem. 这是一个CSS问题。 Your "close" element is right over your showAll element. 您的“关闭”元素就在您的showAll元素上方。 See the corrected fiddle here : 在这里查看更正的小提琴:

http://jsfiddle.net/8U6xq/2/ http://jsfiddle.net/8U6xq/2/

I have just changed this in the css : 我刚刚在CSS中更改了此设置:

.close {
    left: 270px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM