我有一些使用php显示的嵌套记录,每个记录中都包含一个提交按钮。当用户点击一个特定的记录时,它能够正确地发送到数据库。但是按钮应该被切换的问题以及当您提交特定记录而不是仅切换该特定按钮时,每个记录上的所有按钮都会切换。在嵌套记录中切换一行中的特定按钮
HTML
<form method="post" action="" class="input_form">
<label for="item"></label>
<input type="text" name="item" id="item" />
<input type="submit" name="button" id="button" value="Submit" class="input1" />
</form>
<form method="post" action="" class="input_form">
<label for="item"></label>
<input type="text" name="item" id="item" />
<input type="submit" name="button" id="button" value="Submit" class="input1" />
</form>
<form method="post" action="" class="input_form">
<label for="item"></label>
<input type="text" name="item" id="item" />
<input type="submit" name="button" id="button" value="Submit" class="input1" />
</form>
JS
$(document).ready(function() {
$(".input_form").on('submit', function(event) {
$('.input1,.input2').toggleClass('input2', 'input');
event.preventDefault();
if ($('.input2').hasClass('inpu2')) {
data = $(this).serialize();
$.ajax({
type: "POST",
url: "http://localhost/myapp/scripts/inputs.php",
data: data
}).success(function() {});
} else {
if ($('.input').hasClass('input')) {
data = $(this).serialize();
$.ajax({
type: "POST",
url: "http://localhost/myapp/scripts/input_delete.php",
data: data
}).success(function() {});
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
请告诉我们您的HTML代码(这是生成)。你是什么意思的“指针” - 只有swotch类input2和输入? – Seb
'$('。input')。hasClass('input')'。严重? – Fefux
我的意思是当我提交一个特定的行而不是该按钮更改类时,所有按钮类的更改 – user6579134