提交没有表格的表格

问题描述:

This might look as the dumb question, but I hope it's not. I have a PHP file delete.php that will delete selected users (it is not ready yet, but I will write it after I finish my HTML model). So, on my HTML model I have the following:

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

This sexybutton is the button styling I've downloaded. So, how to make it post the selected user list to a PHP file without putting a <form> tag inside (it will brake all the structure otherwise and will not be valid)?

I could use jQuery (or JS), but I still do not know how to do this. If PHP would have something like "onclick" function :)

Thank you in advance.

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

   &lt; li&gt;&lt; button class =“sexybutton”&gt; 
&lt; span&gt;&lt; span&gt;&lt; span class =“add”&gt;添加&lt; / span&gt;&lt; / span&gt;&lt; / span&gt; \  n&lt; / button&gt;&lt; / li&gt; 
  code>  pre> 
 
 

sexybutton code>是我下载的按钮样式。 那么,如何让它将所选用户列表发布到PHP文件中而不在其中放入&lt; form&gt; code>标记(否则它会制动所有结构并且无效)? p>

我可以使用jQuery(或JS),但我仍然不知道如何做到这一点。 如果PHP会有类似“onclick”的功能:) p>

提前谢谢。 p> div>

You can send an ajax request without a form, like this :

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

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

just create the data you need, and send it ?

<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.