Javascript 显示href链接到div
我想在Javascript 显示href链接到div,javascript,jquery,Javascript,Jquery,我想在标记中显示href链接,这样当我按下菜单或列表中的任何内容时,它将在div中打开,并将显示作为其id。 我已经把菜单做好了 <div class="menu"> <a href="http://stackoverflow.com" onkeydown="myFunc()">HOME</a> </div> <div id="display"></div> 我对javascript了解不多,但我认为javascr
标记中显示href
链接,这样当我按下菜单或列表中的任何内容时,它将在div中打开,并将显示作为其id
。
我已经把菜单做好了
<div class="menu">
<a href="http://stackoverflow.com" onkeydown="myFunc()">HOME</a>
</div>
<div id="display"></div>
我对javascript了解不多,但我认为javascript代码实际上是错误的,如果有人能帮助我,我将不胜感激。我想显示href
您需要获取href
属性,以便使用.prop()
我想显示href
您需要获取href
属性,以便使用.prop()
如果您的意思是检索页面并将其放置在div中:
// bind click event to all anchors within .menu
$('.menu a').click(function(e){
// fetch the page using AJAX and place the results in #display
$('#display').load(this.href);
// prevent navigating away from the page (default action of anchor)
e.preventDefault();
});
(或者可能只是我,但问题似乎很难理解。:耸耸肩:)如果您的意思是检索页面并将其放在div中:
// bind click event to all anchors within .menu
$('.menu a').click(function(e){
// fetch the page using AJAX and place the results in #display
$('#display').load(this.href);
// prevent navigating away from the page (default action of anchor)
e.preventDefault();
});
(或者可能只是我,但问题似乎很难理解。:耸耸肩:)我们可以使用iframe在中显示链接我们可以使用iframe在中显示链接这是我的版本
HTML
<div class="menu">
<a id="xxx" href="http://stackoverflow.com" onkeydown="myFunc()">HOME</a>
</div>
<div id="display"></div>
这是我的版本
HTML
<div class="menu">
<a id="xxx" href="http://stackoverflow.com" onkeydown="myFunc()">HOME</a>
</div>
<div id="display"></div>
FWIW,.prop
更适合于href
、id
和其他标准DOMNode属性。FWIW,.prop
更适合于href
、id
和其他标准DOMNode属性。
<div class="menu">
<a id="xxx" href="http://stackoverflow.com" onkeydown="myFunc()">HOME</a>
</div>
<div id="display"></div>
$(document).ready(function() {
var data = $("a#xxx").attr("href");
$('#display').html(data);
});