使用Java脚本或jquery

我使用svg标签创建了很多形状,这些形状又存储在js变量中。我想使用js将组克隆并附加到具有唯一ID的svg元素上。

var ped_pb = '<g transform="scale(1.5)" stroke-width=".0005"><path i:knockout="Off" fill-rule="evenodd" clip-rule="evenodd" d="M10.411,0.506V13.17h12.697V0.506H10.411z"/><g> <defs><path id="XMLID_1_" d="M0,0.253h23.87v23.809H0V0.253z"/>                        </defs>                     <clipPath id="XMLID_2_"><use xlink:href="#XMLID_1_" /></clipPath><path i:knockout="Off" clip-path="url(#XMLID_2_)" fill="none" stroke="#000000" stroke-width="1.0131" stroke-miterlimit="8" d="M10.411,0.506h12.697V13.17H10.411V0.506z"/></g><g stroke-width=".000000000000000000005"><path i:knockout="Off" clip-path="url(#XMLID_4_)" stroke="#000000"  stroke-width="0.0317" stroke-linejoin="round" stroke-miterlimit="10" d="M1.523,23.777l7.555-8.422l-1.523-1.361l-7.523,8.422L1.523,23.777zM7.904,21.782l1.777-8.611l-8.38,2.723c-0.54,0.158-0.825,0.729-0.667,1.267c0.19,0.538,0.762,0.823,1.301,0.665l6.698-2.185l-1.301-1.172l-1.429,6.902c-0.095,0.254,1.076,0.794,1.203C7.269,22.668,7.777,22.321,7.904,21.782z"/></g></g>';

我需要一个js函数,以便根据需要将上述存储在变量中的形状填充到不同x或y坐标的svg元素中。

xuming_11 回答:使用Java脚本或jquery

我通过以下方式实现了目标

-- delete function if we already have it
IF object_id(N'ConvertLocalDateToUtc',N'FN') IS NOT NULL
    DROP FUNCTION ConvertLocalDateToUtc
GO

DECLARE @SQLString nvarchar(MAX);  

-- build server version specific function

-- if SQL Server 2016 or later,this takes account of historical daylight saving times
IF (SELECT CAST(SERVERPROPERTY('ProductMajorVersion') AS INT)) >= 13
BEGIN
SET @SQLString = N'
CREATE FUNCTION [dbo].[ConvertLocalDateToUtc]
(
    @LocalDate DATETIME2,@LocalZone NVARCHAR(128)
)
RETURNS DATETIME2
AS
BEGIN
    DECLARE @convertedDate DATETIME2;
    DECLARE @ZonedLocalDate DATETIMEOFFSET = @LocalDate AT TIME ZONE @LocalZone;
    DECLARE @ZonedUtcDate DATETIMEOFFSET = @ZonedLocalDate AT TIME ZONE ''UTC'';
    SET @convertedDate = CAST(@ZonedUtcDate AS DATETIME2);
    RETURN(@convertedDate);  
END
';
END
ELSE
BEGIN
-- if earlier than SQL Server 2016 this uses the current time zone
-- which may or may not be the same DST as historical dates
SET @SQLString = N'
CREATE FUNCTION [dbo].[ConvertLocalDateToUtc]
(
    @LocalDate DATETIME2,@LocalZone NVARCHAR(128)
)
RETURNS DATETIME2
AS
BEGIN
    DECLARE @convertedDate DATETIME2;
    SET @convertedDate = DATEADD(MI,(DATEDIFF(MI,SYSDATETIME(),SYSUTCDATETIME())),@LocalDate);
    RETURN(@convertedDate);  
END
';
END

-- run the sql to create the function
EXECUTE sp_executesql @SQLString;
var ped_pb = '<g transform="scale(1.5)" stroke-width=".0005" style="border: 1px dashed black;"><path i:knockout="Off" fill-rule="evenodd" clip-rule="evenodd" d="M10.411,0.506V13.17h12.697V0.506H10.411z"/><g> <defs><path id="XMLID_1_" d="M0,0.253h23.87v23.809H0V0.253z"/>						</defs>						<clipPath id="XMLID_2_"><use xlink:href="#XMLID_1_" /></clipPath><path i:knockout="Off" clip-path="url(#XMLID_2_)" fill="none"  stroke-width="1.0131" stroke-miterlimit="8" d="M10.411,0.506h12.697V13.17H10.411V0.506z"/></g><g stroke-width=".000000000000000000005"><path i:knockout="Off" clip-path="url(#XMLID_4_)"   stroke-width="0.0317" stroke-linejoin="round" stroke-miterlimit="10" d="M1.523,23.777l7.555-8.422l-1.523-1.361l-7.523,8.422L1.523,23.777zM7.904,21.782l1.777-8.611l-8.38,2.723c-0.54,0.158-0.825,0.729-0.667,1.267c0.19,0.538,0.762,0.823,1.301,0.665l6.698-2.185l-1.301-1.172l-1.429,6.902c-0.095,0.254,1.076,0.794,1.203C7.269,22.668,7.777,22.321,7.904,21.782z"/></g></g>';
function clone(){

 
 var element = document.createElementNS('http://www.w3.org/2000/svg','g');
 element.setAttributeNS(null,'id','lk');
 element.innerHTML= ped_pb;
 gg.appendChild(element)
 
 element = document.createElementNS('http://www.w3.org/2000/svg','lk1');
 element.setAttributeNS(null,'transform','translate(40,80)');
 element.setAttributeNS(null,'fill','#0FF');
 element.innerHTML= ped_pb;
 gg.appendChild(element)
 
 
 element = document.createElementNS('http://www.w3.org/2000/svg','lk2');
 element.setAttributeNS(null,'translate(80,120)');
 element.setAttributeNS(null,'#f00');
 element.innerHTML= ped_pb;
 gg.appendChild(element)
}

  document.addEventListener("onload",init(),false)
            function init()
            {
                //clone()
				clone()
                }

本文链接:https://www.f2er.com/3052154.html

大家都在问