简体   繁体   English

在JQuery中附加到div

[英]Appending to a div in JQuery

At first imgButton is a string of text containing HTML for an img tag. 首先,imgButton是一个包含img标记HTML的文本字符串。 However, this variable is later turned into the results of .detach() of the img tag. 但是,此变量后来变为img标记的.detach()的结果。 The problem in the below code is that it does not display the image that it did previously, but instead [object Object] is displayed. 下面代码中的问题是它不显示它先前执行的图像,而是显示[object Object]。 It does display the correct image when using imgButton inside of its own append statement or appendTo. 当在其自己的append语句或appendTo中使用imgButton时,它会显示正确的图像。 Is there a way to print out imgButton in the same append statement as the other strings and have it display properly? 有没有办法在与其他字符串相同的append语句中打印imgButton并正确显示?

I hope I explained the problem properly. 我希望我能正确解释这个问题。

$("#search_prams").append("<div class='advsearchparam'><select class='searchparam'>" +
        "<option value='test'>test</option>" +
        "<option value='test1'>test1</option>" +
        "</select><input class='search' type='text'><button class='remove' id='remove1'>X</button></div>"+ imgButton);

If it says that imgButton is an object then it is not a string try this, 如果它说imgButton是一个object那么它不是一个string试试这个,

$("#search_prams").append("your div string here ")
                  .append(imgButton);// append img button here

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

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