我有此代码(按钮):
<a href="https://www.google.com" target="_blank">
<button type="button" onclick="self.close()"
style="background:url('/url/to/image') no-repeat left top; height:48px; width:412px; border: none;">
</button>
</a>
,我想在单击后隐藏此按钮。最简单的方法是什么?
答案 0 :(得分:2)
我要走的路是这样的
jQuery(function($) {
$('button').on('click', function() {
$(this).hide();
});
});
仍然不确定“最简单” 的含义。对我来说,它是上面的代码:我避免在HTML标记内的DOM中间编写Javascript。将它们全部包裹在<script>
标签中(通常在</body>
之前)比较方便。
但这是我的看法。
答案 1 :(得分:1)
最简单的?我想这是一个见解,您可以调用jquery的hide()
吗?
<a href="https://www.google.com" target="_blank">
<button type="button" onclick="$(this).hide(); return false;"
style="background:url('/url/to/image') no-repeat left top; height:48px; width:412px; border: none;">
</button>
</a>
您已将其包装在锚定标记中,因此,如果要阻止默认行为重定向到https://www.google.com/
答案 2 :(得分:1)
我会尝试:
<html>
<body>
<button type="button" onclick="this.style.display='none';" style="height:1em;"></button>
</body>
</html>
答案 3 :(得分:0)
最简单一词可能具有多种形式的解决方案。我认为for i in range(0, len(x['x']['out'])):
print(x['x']['out'][i]['addr'])
可能是运行时解决速度更快的问题。
display:none
答案 4 :(得分:0)
我认为最简单的方法是使用addEventListener
来监听按钮上的点击事件。您的回调函数将隐藏元素:
document.querySelector('button').addEventListener('click', e => e.target.style.display = 'none');
<button type="button">Click to hide</button>
答案 5 :(得分:0)
谢谢大家的回答。对我来说,最简单的解决方案是Giulio Bambini,Sean T和MyGeertRo:)