我有一个 HTML 页面,其中有很多不同的 DIV,我想打印出用户单击的 DIV 并隐藏所有其余部分。
有人可以告诉我如何用 JavaScript 做到这一点吗?
<html>
<head>
<title>Print Demo</title>
<script type="text/javascript">
<!-- MY JAVASCRIPT FUNCITON -->
</script>
</head>
<body>
<div id="div1">
<a href="<JSMethod>">Print the page with this div</a>
</div>
<div id="div2">
<a href="<JSMethod>">Print the page with this div</a>
</div>
<div id="div3">
<a href="<JSMethod>">Print the page with this div</a>
</div>
</body>
</html>
最佳答案
这只是为了扩展pimvdb's answer .
jQuery:
$("a").on("click", function(){
$("div").hide();
$(this).parent().show();
});
或者按照建议:
$("a").on("click", function(){
$("div").hide();
$(this).closest("div").show();
});
关于javascript - 打印带有已单击的 div 的 HTML 页面并隐藏其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10380605/