gpt4 book ai didi

Jquery 选择 checkbix 并构建要发送到数据库的 url

转载 作者:行者123 更新时间:2023-12-01 05:54:57 25 4
gpt4 key购买 nike

Jsfiddle:http://jsfiddle.net/Xytvg

每个复选框都有 ID 和值,例如,如果我选中了合格复选框或不合格复选框。

我想禁用该复选框,具体取决于单击的是哪个复选框,并且我希望在成功回调函数上完成此操作。

下面是我的代码:

$( "input[type=checkbox]" ).on( "click",function( e ){

var preview = $("#preview").html('');

// ** just a loader a gif image
preview .html('<img src="../images/loader.gif" alt="Uploading...."/>');

// ** this is the value of the checkbox
var input = $(this).val();

// ** here i am pulling the id value
var id = $(this).attr('id');


$.ajax({
// here i am trying to build url to be send to the action.php
// i will get the id and the value depends on which checkbox was clicked
// action.php?id=1&value=2

url: 'action.php?id='+id+'&value='+input,
type: "POST",
success: function( response )
{
// here i want to figure out which checkbox was clicked and disabled it
}
});

e.preventDefault();

});



<div id="preview"></div><!--loader gif-->

<p>
USA
<input type="checkbox" id="1" value="2" />Qualified OR
<input type="checkbox" id="1" value="3" /> Unqualifed
</p>

<p>
UK
<input type="checkbox" id="2" value="2" />Qualified OR
<input type="checkbox" id="2" value="3" /> Unqualifed
</p>

<p>
EGY
<input type="checkbox" id="3" value="2" />Qualified OR
<input type="checkbox" id="3" value="3" /> Unqualifed
</p>

最佳答案

将复选框分配给点击处理程序中的变量,如下所示:

$( "input[type=checkbox]" ).on( "click",function( e ) {
var $checkbox = $(this);
// rest of click handler code

然后在成功回调中您可以像这样禁用它:

$.ajax({
url: 'action.php?id='+id+'&value='+input,
type: "POST",
success: function( response )
{
$checkbox.attr('disabled', true);
}
});

关于Jquery 选择 checkbix 并构建要发送到数据库的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16723582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com