我正在尝试删除div按钮单击,但问题是我需要按钮来删除它包含的 div,而不将 div 的 id 传递给删除按钮
所以最后的这段代码应该能够删除 div 而无需传递 div 的 id,而是依赖于传递this引用
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(document).on('mouseenter', '#divbutton', function() {
$(this).find(":button").show();
}).on('mouseleave', '#divbutton', function() {
$(this).find(":button").hide();
});
});
</script>
<style>
#divbutton {
height: 100px;
background: #0000ff;
}
#divbutton2 {
height: 100px;
background: #0000ff;
}
#divbutton3 {
height: 100px;
background: #0000ff;
}
</style>
</head>
<body>
<div id="divbutton">
<button type="button" style="display: none;" id="i" onclick="document.body.removeChild(document.getElementById('divbutton'))">Hello</button>
</div>
<div id="divbutton2">
<button type="button" style="display: none;" id="i" onclick="document.body.removeChild(document.getElementById('divbutton2'))">Hello …Run Code Online (Sandbox Code Playgroud) 您好我想bb()按钮点击执行功能.
我尝试了下面的代码,但它没有用.
echo "<div class ='i2' id=".$x.">";
echo "<button type='button' style='display: none;' id='i' name='delete' onclick='document.body.removeChild(this.parentNode)'>";
echo"</button>";
echo "</div>";
<?php
function bb()
{
echo "hello";
}
if (isset($_GET['delete'])) {
bb();
}
?>
Run Code Online (Sandbox Code Playgroud)