嗨,我正试图通过ID从网页中加载一个元素。
我的代码从标签的'href‘属性读取url,然后加载页面。我要剥掉文件锚。
此脚本工作,但不会丢弃环绕声元素并加载整个页面。
<script type="text/javascript">
$(function() {
var a_href = $('#pycom').attr('href').split('#');
$('div#pop-up').load(a_href[0] + '#synopsis');
});
</script>
<body>
<a id="pycom" href="content/documentation/CommandsPython/ls.html#hFlags">ls</a>
</body>上面的链接按照上面的'html‘代码在本地存在于我的服务器(XAMPP)上。
下面是我想要提取的元素。
<p id="synopsis">
<code>
xform([objects...],
[<a href="#flagabsolute">absolute</a>=<i>boolean</i>],
[<a href="#flagboundingBox">boundingBox</a>=<i>boolean</i>],
.....
.....
</code>
谢谢
杰米
发布于 2015-08-06 01:57:06
好的解决了。我使用的是jQuery 2.4.1,它显然有一个应该修复的bug。但似乎不是??见这里http://bugs.jquery.com/ticket/14773
我使用的是jQuery 1.11.3
下面是我的最后代码:
<script type="text/javascript" src="content/scripts/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(function() {
var moveLeft = -10;
var moveDown = 10;
$('a#pycom').hover(function(e) {
var a_href = $(this).attr('href').split('#');
$('#pop-up').load(a_href[0] + ' #synopsis');
$('div#pop-up').show().css('top', e.pageY + moveDown).css('left', ((e.width/100)*1) + moveLeft);
}, function() {
$('div#pop-up').hide();
});
});
</script>以下使用.get的方法的工作原理也完全相同,但可以在回调中处理返回的字符串。在这种情况下,请求的选定元素的尾部部分.非常好的东西。
$('a#pycom').hover(function(e) {
var a_href = $(this).attr('href').split('#');
$.get(a_href[0], function(response) {
$('#pop-up').html($(response).filter('#synopsis').html().split('<br>')[0]);
});
});现在像老板一样拥有jQuery!!

感谢所有帮助我的人。
丘尔!
J
发布于 2015-08-05 07:32:51
At first get your page, and then inside the
content find your element with id named 'synopsis' as below:
var a_href = $('#pycom').attr('href').split('#');
$("div#pop-up").load(a_href[0] + " #synopsis" );它应该可以工作,但在此之前检查浏览器是否支持混合内容。如果url在https中包含http,那么浏览器可能不支持,在这种情况下,您必须不允许在浏览器中进行检查。
谢谢。
发布于 2015-08-05 05:34:08
您不应该在URL中留出任何空间。在“#大纲”前面有一个空格。
$('div#pop-up').load(a_href[0] + '#synopsis');https://stackoverflow.com/questions/31824066
复制相似问题