jQuery를 통해 경로를 업데이트 한 후 SVG 이미지가 검정색으로 바뀝니다.

StackOverflow https://stackoverflow.com//questions/22081551

  •  24-12-2019
  •  | 
  •  

문제

다음과 같은 HTML 코드가 있습니다

<div>
    <a id="cover"></a>
    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 510 680">
    <rect x="0" y="0" fill="#000007" width="510" height="680"/>
    <image width="510" height="680" xlink:href="../images/MSRCover.png" transform="translate(0 0)" />
    </svg>
</div>
.

jQuery로 이미지의 경로를 바꾸려고하고 이미지가 검은 색으로 변합니다.

$ = cheerio.load(data);
$('image').each(function()
{
    var $img    = $(this);
    $(this).attr('xlink:href','My PATH').html();
});
.

node.js와 모듈 Cheremio를 사용하고 있습니다.

감사합니다

도움이 되었습니까?

해결책

jQuery .ATTR 방법은 네임 스페이스를 이해하지 못합니다.대신 정상적인 DOM SetAttributens를 사용하십시오.

$(this)[0].setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "My PATH");
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top