我正在尝试从布局本身中删除单击时的按钮。但到目前为止还无法做到这一点。我是第一次接触ajax和jQuery。我有一个div在网页上显示待决的行动在按钮的形式,现在我想删除每个按钮,当用户点击它。此网页每隔1分钟自动刷新一次,所有这些挂起的操作都存储在一个会话变量中。
现在我没有办法将这个按钮id发送到另一个php脚本,这样它就可以从会话数组中删除它。
我试着跟踪..。
<script type='text/javascript'src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
function HideButton(butId)
{
$('#'+butId).hide();
deleteButton(butId);
}
</script>
<script>
function deleteButton(id) {
$.ajax({
url: "delete_button.php",
type: "POST",
data: "id=" + id,
success: function(response) {// Response handler}
});
}
</script>
<?php // here is my php code ..
//displaying button as follows in a loop
echo "<br><button type='button' id='".$id."' onclick=javascript:HideButton('".$id."') >".$pendingAction[$id]." </button>";目前还没有发现任何成功。
发布于 2014-07-22 17:50:27
使用jQuery remove
DOM:
<div class="container">
<div class="hello">Hello</div>
<div class="goodbye">Goodbye</div>
</div>jQuery:
$( ".hello" ).remove();输出:
<div class="container">
<div class="goodbye">Goodbye</div>
</div>发布于 2014-07-22 17:57:13
你可以通过下面的方法做到这一点;
HTML:
<div>
<input type="button" name="button1" id="button1" value="Button 1"/>
<input type="button" name="button2" id="button2" value="Button 2"/>
</div>JS:
$("input[type='button']").on("click", function() {
var btnId = $(this).attr("id");
$(this).remove();
// Uncomment below to activate ajax call
//deleteButton(btnId);
})
function deleteButton(id) {
$.ajax({
url: "delete_button.php",
type: "POST",
data: "id=" + id,
success: function(response) {// Response handler}
});
}PHP(delete_button.php):
<?php
var btnId = $_POST["id"];
// delete from session by using $btnId发布于 2014-07-22 17:57:35
可以使用jQuery remove操作
$('.removeButton').live(function () { $(this).remove();
`});`或者,您也可以在单击按钮时将其隐藏
$('.removeButton').live(function () { $(this).hide();
`});`https://stackoverflow.com/questions/24884043
复制相似问题