0

我对这一行有点放屁:

jQuery("#image-div").html("<img src='get.php?id_no='" + id + ">");

我正在尝试将<img>标签与变量连接起来,id但我似乎无法正确引用引号。愚蠢的错误,我知道,但它只是逃避我。我能得到一点帮助吗?

4

3 回答 3

4

看起来你放错了撇号。

jQuery("#image-div").html("<img src='get.php?id_no=" + id + "'>");
于 2013-03-03T05:11:07.063 回答
1

您的代码中有一个放错位置的单引号。

jQuery("#image-div").html("<img src='get.php?id_no='" + id + ">");
                                                // ^ This one here

它应该是

jQuery("#image-div").html("<img src='get.php?id_no=" + id + "'>");
                                                          // ^ Should be here
于 2013-03-03T05:14:13.457 回答
1

我真的不创建像你应该严格的 DOM 元素:

jQuery("#image-div").appendTo(
                         $("<img/>")
                             .attr("src", "get.php?id_no" + id)
                             .attr("alt", "someThing") )

我知道这是更多的打字,但现在更有意义。

于 2013-03-03T08:41:42.817 回答