小编use*_*338的帖子

querySelectorAll - 如何只获取某个div中的元素

我想限制这个选择器,只给我一个id为"divId1"的div里面的结果

var polys = document.querySelectorAll('polygon,polyline');
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

javascript svg

5
推荐指数
3
解决办法
4943
查看次数

使用PHP循环访问SVG元素

如何使用PHP循环访问SVG元素?

<?php

$svgString = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="overflow: hidden; position: relative;" width="9140" version="1.1" height="3050">
<rect x="0" y="0" width="9140" height="3050" r="0" rx="0" ry="0" fill="#FFFF00" stroke="#000"/>
<image x="-101.5" y="-113.5" width="203" height="227" xlink:href="1.jpg" stroke-width="1"></image>
<image x="-201.5" y="-213.5" width="103" height="127" xlink:href="2.jpg" stroke-width="1"></image>
</svg>';

$svg = new SimpleXMLElement( $svgString );
$result = $svg->xpath('//image');
echo count( $result ); 
for ($i = 0; $i < count($result); $i++) 
{
    var_dump( $result[$i] );
}
Run Code Online (Sandbox Code Playgroud)

count($result) 返回0,因此省略循环.

我究竟做错了什么?

php xml xpath svg

4
推荐指数
1
解决办法
4783
查看次数

如何使用PHP获取SVG标记内容

我想用PHP获取SVG标记内容.

test.svg:

<?xml version="1.0" encoding="utf-8"?>
<!-- comment  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
 width="202.5px" height="226.084px" viewBox="0 0 202.5 226.084" enable-background="new 0 0 202.5 226.084" xml:space="preserve">
   <g>
        <path d="M0,13.628c47.7940,13.628z"/>
        <polygon points="108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854  "/>
        <path fill="none" stroke="#000000" d="M114.55,223.959"/>
   </g>
   <g>       
        <path fill="none" stroke="#000000" d="M114.55,223.959"/>
   </g>
   <anythingElse>       
        <path fill="none" stroke="#000000" d="M114.55,223.959"/>
   <anythingElse>       
</svg>
Run Code Online (Sandbox Code Playgroud)

PHP:

$svg = new SimpleXMLElement( file_get_contents( 'test.svg' )  );

$svg->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg');
$svg->registerXPathNamespace('xlink', 'http://www.w3.org/1999/xlink');
Run Code Online (Sandbox Code Playgroud)

现在,我想将svg标记内容作为字符串.

期望的结果(硬编码示例):

$content =  '<g>
    <path …
Run Code Online (Sandbox Code Playgroud)

php xml svg namespaces simplexml

4
推荐指数
1
解决办法
1万
查看次数

回调此上下文

在App中:

var bootstrap = new Bootstrap();
bootstrap.init( this, this.onBootstrapComplete );
Run Code Online (Sandbox Code Playgroud)

在Bootstrap中:

this.init = function( app, completeHandler ){
    _app = app;
    _completeHandler = completeHandler;
        ...
}

...

var _allReady = function(){
        _completeHandler( _app );
}
Run Code Online (Sandbox Code Playgroud)

回到应用程序:

this.onBootstrapComplete = function( app )
{
        app.something();
        app.someValue = ...
}
Run Code Online (Sandbox Code Playgroud)

我想在onBootstrapComplete中获取此上下文.它工作但看起来不正确:)

如果让我们说,我想直接从应用程序调用onBootstrapComplete,我会打电话给它这个 .onBootstrapComplete(本).

我怎么能这样做,所以我的onBootstrapComplete看起来像这样:

this.onBootstrapComplete = function()
{
        this.something();
        this.someValue = ...
}
Run Code Online (Sandbox Code Playgroud)

javascript callback this

1
推荐指数
1
解决办法
1576
查看次数

标签 统计

svg ×3

javascript ×2

php ×2

xml ×2

callback ×1

namespaces ×1

simplexml ×1

this ×1

xpath ×1