Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery .不起作用_Jquery - Fatal编程技术网

Jquery .不起作用

Jquery .不起作用,jquery,Jquery,我试图做的是在关闭标记之前的*test123之后追加表及其内容,但它不起作用,不确定此代码中有什么错误* JQUERY代码 $('span[itemprop="description"]').append($('C1')); <span itemprop='description'>test123</span> this is outside of span tag<br> <table width="200" bord

我试图做的是在关闭
标记之前的*test123
之后追加表及其内容,但它不起作用,不确定此代码中有什么错误*

JQUERY代码

$('span[itemprop="description"]').append($('C1'));
  <span itemprop='description'>test123</span>
        this is outside of span tag<br>

     <table width="200" border="1" class="C1">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>

</table>
HTML代码

$('span[itemprop="description"]').append($('C1'));
  <span itemprop='description'>test123</span>
        this is outside of span tag<br>

     <table width="200" border="1" class="C1">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>

</table>
test123
这超出了span标记的范围
1. 2. 3.
itemprop
不是有效的HTML属性。我不确定jQuery一开始是否允许这样做。您将希望改用
数据项prop

$('C1')
表示您有一个(同样无效的)
元素。您需要使用
$('.C1')
在类上进行选择

$('span[itemprop="description"]').append($('.C1').clone());

您没有在选择器添加
中定义
。另外,您将对象附加到span而不是html,因此我使用了
.clone
及其对我有效的功能。

您应该附加html,而不是对象。您可以这样做:

$('span[itemprop=description]').append($('.C1').html());

C1不是有效的选择器。你需要使用

$('span[itemprop="description"]').append($('.C1'))

您忘记了一个

$('span[itemprop="description"]').append($('.C1'));

将jQuery代码更改为:

$('span[itemprop="description"]').append($('.C1'));

另外,
append
是将内容附加到span元素中,而不是在它之后,也许它只是一个函数。缺少:
$('.C1')
以获取类C1的元素?这就是你想做的吗?这有关系吗,代码对他想做的事情起作用。问题不在于这是否有效HTML@s.lenders当前位置当你回答时,我正在编辑我的答案。我之前给出了一个无效的答案,因为我认为这是一个不同的问题,所以必须快速编辑它。是的,无效的HTML确实很重要,因为这是一种不好的做法,没有必要这样做。此外,我也不知道为什么这一点被否决,以及这个问题的所有其他答案……解释否决票……不管它是否是HTML属性,但我们仍然可以选择它……尝试一下……它总是有效的。@user580950我也这么说了,所以为什么我被否决了。???即使这样也不起作用,因为它将在其中获取对象而不是html。@Dipesh Parmar,您可以使用jquery对象作为参数。