Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
Javascript 如何选择特定的<;g>;在<;文本>;作为它的子级使用jQuery?_Javascript_Jquery_Svg - Fatal编程技术网

Javascript 如何选择特定的<;g>;在<;文本>;作为它的子级使用jQuery?

Javascript 如何选择特定的<;g>;在<;文本>;作为它的子级使用jQuery?,javascript,jquery,svg,Javascript,Jquery,Svg,我有如下html <svg> <g> <rect></rect> <text> abc </text> </g> <g> <rect></rect> <text> def </text> </g> </svg> abc def

我有如下html

<svg>
    <g>
        <rect></rect>
        <text> abc </text>
    </g>

    <g>
        <rect></rect>
        <text> def </text>
    </g>
</svg>

abc
def
我想选择g标记,它的值为“abc”,并且应该向它附加一些其他的文本标记,这样最终的输出将是

    <svg>
    <g>
        <rect></rect>
        <text> abc </text>
        <text> extra added abc </text>
    </g>

    <g>
        <rect></rect>
        <text> def </text>
    </g>
</svg>

abc
额外增加的abc
def

具有()的
g
标记作为目标,
包含()字符串
abc
text
标记,然后像这样将元素附加到该
g
标记上

$('g:has(text:contains("abc"))').append($('<text />', {text : ' extra added abc '}));
$('g:has(text:contains(“abc”))).append($('',{text:'extra added abc'}));

具有()的
g
标记作为目标,
包含()字符串
abc
text
标记,然后像这样将元素附加到该
g
标记上

$('g:has(text:contains("abc"))').append($('<text />', {text : ' extra added abc '}));
$('g:has(text:contains(“abc”))).append($('',{text:'extra added abc'}));
试试这个:

$(function(){
  $('g text:contains(abc)').closest('g').append('<text> extra added abc </text>');
});
$(函数(){
$('g text:contains(abc)')。最近的('g')。追加('extra added abc');
});
试试这个:

$(function(){
  $('g text:contains(abc)').closest('g').append('<text> extra added abc </text>');
});
$(函数(){
$('g text:contains(abc)')。最近的('g')。追加('extra added abc');
});
$(函数(){
$('g text:contains(abc)')。在('extra added abc')之后;
});
$(函数(){
$('g text:contains(abc)')。在('extra added abc')之后;
});

:感谢您的回复,但我还遇到了另一个问题,通过这种方式,它正确地创建了html代码(在chrome中使用F12进行检查),但不会显示在chrome中(我指的是UI)。。。知道为什么吗?:谢谢你的回复,但我还有一个问题,通过这种方式,它正确地创建了html代码(在chrome中使用F12进行检查),但不会显示在chrome中(我指的是UI)。。。知道为什么吗?