search
HomeBackend DevelopmentPHP Tutorial请问jquery如何删除当前列?

<script type="text/javascript"src="js/jquery.js"></script><link href="css/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /> <script type="text/javascript" src="js/tablecloth.js"></script><?phprequire('inc/page.class.php');require("inc/pdo.php");$selectSpecialContent=$dbc->prepare("select * from naszt");$selectSpecialContent->execute();?><table align="center" cellspacing="0" cellpadding="0"><tr><th>专题名称</th><th>专题类型</th><th>发表时间</th><th>发表ip</th><th>操作</th></tr><?php while($row=$selectSpecialContent->fetch()){ ?><tr id="<?php echo $row['id']?>"><td><?php echo $row['ztname']?></td><td><?php echo $row['zttype']?></td><td><?php echo $row['zttime']?></td><td><?php echo $row['publiship']?></td><td><button><a href="ztselect.php?id=<?php echo $row['id']?>">查看</a></button><button><a href="upzt.php?act=up&id=<?php echo $row['id']?>">修改</a></button><button id="del"><a href="selectzt.php?act=del&id=<?php echo $row['id']?>">删除</a></button></td></tr><?php }; ?></table><script>$(document).ready(function(){$("#del").click(function(){var q=$("tr").attr("id");alert(q);});});</script>

本来是想在tr 加个id  获取到这个id的值删除本行  但好像不行,请教高手


回复讨论(解决方案)

将前端的html输出来才方便别人判断...

将前端的html输出来才方便别人判断...

专题名称 专题类型 发表时间 发表ip               操作
权威的气氛 威联通 2013-12-04 22:40:35 127.0.0.1 查看 修改 删除
额外范围为 网件 2013-12-04 22:41:43 127.0.0.1 查看 修改 删除
的分别是地方 网件 2013-12-04 22:44:33 127.0.0.1 查看 修改 删除
785875857875 网件 2013-12-04 22:56:15 127.0.0.1 查看 修改 删除
fdbsdfbs 网件 2013-12-04 22:59:51 127.0.0.1 查看 修改 删除

你把 连接 包在 button 标记中,连接能生效吗?

简单的改了下,你看看效果和做法

<script>$(function() {  $('.del').click(function() {    $('#'+$(this).attr('id')).remove();  });});</script><table align="center" cellspacing="0" cellpadding="0"><tr><th>专题名称</th><th>专题类型</th><th>发表时间</th><th>发表ip</th><th>操作</th></tr><tr id="1"><td>$row['ztname']</td><td>$row['zttype']</td><td>$row['zttime']</td><td>$row['publiship']</td><td><a href="?id=1">查看</a><button><a href="?act=up&id=1">修改</a></button><button class='del' id=1>删除</button></td></tr></table><?phpprint_r($_GET);

你把 连接 包在 button 标记中,连接能生效吗? 可以   后台实现从数据库删除了,我想在前端页面不刷新的情况下用js将选中的这一行tr在table中删除

看 #4 的删除按钮

看 #4 的删除按钮

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script charset="utf-8" src="js/jquery.js"></script><?phprequire("inc/pdo.php");$selectSpecialContent=$dbc->prepare("select * from naszt");$selectSpecialContent->execute();?><script>$(document).ready(function() {$('.del').bind("click".q);function q(){    $('#'+$(this).attr('id')).remove();}});</script><table align="center" cellspacing="0" cellpadding="0"><tr><th>专题名称</th><th>专题类型</th><th>发表时间</th><th>发表ip</th><th>操作</th></tr><?php while($row=$selectSpecialContent->fetch()){ ?><tr id="<?php echo $row['id']?>"><td><?php echo $row['ztname']?></td><td><?php echo $row['zttype']?></td><td><?php echo $row['zttime']?></td><td><?php echo $row['publiship']?></td><td><button>查看</button><button>修改</button><button class='del' id="<?php echo $row['id']?>">删除</button></td></tr><?php }; ?></table>


为什么点了没反应呢...

看 #4 的删除按钮 前台输出为:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script charset="utf-8" src="js/jquery.js"></script>?<script>$(document).ready(function() {$('.del').bind("click".abc);alert("1");function abc(){	alert("1");    $('#'+$(this).attr('id')).remove();}});</script><table align="center" cellspacing="0" cellpadding="0"><tr><th>专题名称</th><th>专题类型</th><th>发表时间</th><th>发表ip</th><th>操作</th></tr><tr id="2"><td>27878</td><td>威联通</td><td>2013-12-03 23:26:45</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="2">删除</button></td></tr><tr id="6"><td></td><td>威联通</td><td>2013-12-04 17:39:07</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="6">删除</button></td></tr><tr id="7"><td>权威的气氛</td><td>威联通</td><td>2013-12-04 22:40:35</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="7">删除</button></td></tr><tr id="8"><td>额外范围为</td><td>网件</td><td>2013-12-04 22:41:43</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="8">删除</button></td></tr><tr id="9"><td>的分别是地方</td><td>网件</td><td>2013-12-04 22:44:33</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="9">删除</button></td></tr><tr id="10"><td>785875857875</td><td>网件</td><td>2013-12-04 22:56:15</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="10">删除</button></td></tr><tr id="11"><td>fdbsdfbs</td><td>网件</td><td>2013-12-04 22:59:51</td><td>127.0.0.1</td><td><button>查看</button><button>修改</button><button class='del' id="11">删除</button></td></tr></table>

看 #4 的删除按钮 好了 谢谢您,着急写错了一个逗号

本帖最后由 xuzuning 于 2013-12-06 16:44:47 编辑

你也太粗心了吧?
$('.del').bind("click".q);
这样
$('.del').bind("click",q);
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to calculate the total number of elements in a PHP multidimensional array?How to calculate the total number of elements in a PHP multidimensional array?May 15, 2025 pm 09:00 PM

Calculating the total number of elements in a PHP multidimensional array can be done using recursive or iterative methods. 1. The recursive method counts by traversing the array and recursively processing nested arrays. 2. The iterative method uses the stack to simulate recursion to avoid depth problems. 3. The array_walk_recursive function can also be implemented, but it requires manual counting.

What are the characteristics of do-while loops in PHP?What are the characteristics of do-while loops in PHP?May 15, 2025 pm 08:57 PM

In PHP, the characteristic of a do-while loop is to ensure that the loop body is executed at least once, and then decide whether to continue the loop based on the conditions. 1) It executes the loop body before conditional checking, suitable for scenarios where operations need to be performed at least once, such as user input verification and menu systems. 2) However, the syntax of the do-while loop can cause confusion among newbies and may add unnecessary performance overhead.

How to hash strings in PHP?How to hash strings in PHP?May 15, 2025 pm 08:54 PM

Efficient hashing strings in PHP can use the following methods: 1. Use the md5 function for fast hashing, but is not suitable for password storage. 2. Use the sha256 function to improve security. 3. Use the password_hash function to process passwords to provide the highest security and convenience.

How to implement array sliding window in PHP?How to implement array sliding window in PHP?May 15, 2025 pm 08:51 PM

Implementing an array sliding window in PHP can be done by functions slideWindow and slideWindowAverage. 1. Use the slideWindow function to split an array into a fixed-size subarray. 2. Use the slideWindowAverage function to calculate the average value in each window. 3. For real-time data streams, asynchronous processing and outlier detection can be used using ReactPHP.

How to use the __clone method in PHP?How to use the __clone method in PHP?May 15, 2025 pm 08:48 PM

The __clone method in PHP is used to perform custom operations when object cloning. When cloning an object using the clone keyword, if the object has a __clone method, the method will be automatically called, allowing customized processing during the cloning process, such as resetting the reference type attribute to ensure the independence of the cloned object.

How to use goto statements in PHP?How to use goto statements in PHP?May 15, 2025 pm 08:45 PM

In PHP, goto statements are used to unconditionally jump to specific tags in the program. 1) It can simplify the processing of complex nested loops or conditional statements, but 2) Using goto may make the code difficult to understand and maintain, and 3) It is recommended to give priority to the use of structured control statements. Overall, goto should be used with caution and best practices are followed to ensure the readability and maintainability of the code.

How to implement data statistics in PHP?How to implement data statistics in PHP?May 15, 2025 pm 08:42 PM

In PHP, data statistics can be achieved by using built-in functions, custom functions, and third-party libraries. 1) Use built-in functions such as array_sum() and count() to perform basic statistics. 2) Write custom functions to calculate complex statistics such as medians. 3) Use the PHP-ML library to perform advanced statistical analysis. Through these methods, data statistics can be performed efficiently.

How to use anonymous functions in PHP?How to use anonymous functions in PHP?May 15, 2025 pm 08:39 PM

Yes, anonymous functions in PHP refer to functions without names. They can be passed as parameters to other functions and as return values ​​of functions, making the code more flexible and efficient. When using anonymous functions, you need to pay attention to scope and performance issues.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft