0

这可能看起来是个愚蠢的问题,但我希望不是。我有一个 PHP 文件 delete.php 将删除选定的用户(它还没有准备好,但我会在完成我的 HTML 模型后编写它)。所以,在我的 HTML 模型上,我有以下内容:

<li><button class="sexybutton">
  <span><span><span class="add">Add</span></span></span>
</button></li>

sexybutton是我下载的按钮样式。那么,如何使其将选定的用户列表发布到 PHP 文件而不在其中放置<form>标签(否则它将破坏所有结构并且无效)?

我可以使用 jQuery(或 JS),但我仍然不知道该怎么做。如果 PHP 有类似“onclick”的功能:)

先感谢您。

4

2 回答 2

6

您可以发送没有表单的 ajax 请求,如下所示:

$('.sexybutton').on('click', function() {
    var users = $.map( $('li.users'), function(el) {
       return $(el).text();
    });

    $.ajax({
        url : 'delete.php',
        data: users
    });
});

只需创建您需要的数据并发送它?

于 2013-09-08T20:37:07.940 回答
-1
<form id="your_form">
<ul>
<li><button class="sexybutton" onclick="$('#your_form').submit();">
  <span><span><span class="add">Add</span></span></span>
</button></li>
</ul>
</form>

explanation:

wrap your existing code with form element, give some unique id to your form (e.g. your_form) and then add attribute onclick to your button and fill it with some jquery syntax (or pure javascript if you wish):

$('#your_form').submit();

this will do the submit job.

于 2013-09-08T20:39:09.907 回答