所以我有一个脚本,需要通过类名称的P父DIV级中的每个标记,entry-content并使用google翻译API翻译每个标记.
因此,当用户单击链接以将页面从英语翻译为西班牙语时,将运行以下函数:
function spanish() {
$(".entry-content p").each(function(){
var text = $(this).html();
google.language.detect(text, function(result) {
google.language.translate(text, "en", "es", function(result) {
if (result.translation) {
alert($(this).html()); //outputs NULL
$(this).html(result.translation); //doesn't work
}
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
问题是当iIget到内部函数$(this).html()回复NULL并且我无法更改当前元素html以便将其更改为新的翻译文本.
所以我想我的问题是:如何将当前选中的元素传递给嵌套函数?
谢谢
所以这个xpath查询让我抓狂.我正在尝试做的是搜索一个特定课程类型的高尔夫球场的xml文件(在这种情况下是与谷歌地图api一起使用的kml文件)并抓取每个匹配的<Placemark>元素,以便我可以创建一个新的xml对象结果,以便我可以进一步使用新查询进行过滤.问题是我似乎无法弄清楚如何获得每个匹配<Placemark>元素
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Placemark id="placemark3">
<name>Test Country Club</name>
<description>
<![CDATA[
<div class="contact">Post Office Box 329 <a href="#" target="_blank">website</a></div>
]]>
</description>
<alpha>a</alpha>
<position>2</position>
<type>Public/Daily Fee</type>
<styleUrl>#nineholeStyle</styleUrl>
<Point>
<coordinates>-79.285576,37.111809</coordinates>
</Point>
</Placemark>
</Document>
</kml>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
//trying to get any Placemark element where type child matches a specific query
//in this case we want to search for Public/Daily Fee and return the placemark and everything inside …Run Code Online (Sandbox Code Playgroud)