gpt4 book ai didi

javascript - 如何使用 javascript 将选中的复选框值传递到下一页

转载 作者:行者123 更新时间:2023-12-02 17:54:46 28 4
gpt4 key购买 nike

我正在从数据库中检索值并将其显示在带有复选框的 html 表中。我还有按钮,当用户选中复选框时,它会传递 rowid 并重定向下一页。如果用户未选中复选框并选中该按钮不会传递 rowid,也不会重定向。

我的问题是,当检查 html 表中的第一行并按下按钮时,它的工作正常,但如果我检查 html 表中的第二行并单击按钮,它不会执行任何操作

下面是我的代码

<tbody id="fbody" class="fbody" style="width:1452px" >    
<?php

$clientid=$_GET['clientid'];
if($clientid!=""){
$sql = mysql_query("SELECT * FROM billingdatainputandexport WHERE clientid = '$clientid'");

while($rows=mysql_fetch_array($sql))
{
if($alt == 1)
{
echo '<tr class="alt">';
$alt = 0;
}
else
{
echo '<tr>';
$alt = 1;
}

echo '<td style="width:118px" class="edit clientid '.$rows["id"].'">'.$rows["clientid"].'</td>
<td id="CPH_GridView1_clientname" style="width:164px" class="edit clientname '.$rows["id"].'">'.$rows["clientname"].'</td>
<td id="CPH_GridView1_billingyear" style="width:168px" class="edit billingyear '.$rows["id"].'">'.$rows["billingyear"].'</td>
<td id="CPH_GridView1_billingmonth " style="width:169px" class="edit billingmonth '.$rows["id"].'">'.$rows["billingmonth"].'</td>
<td style="width:167px" class=" '.$rows["id"].'">
<input name="nochk" value=" '.$rows["id"].'" type="submit" style="margin:0 0 0 49px;background-image: url(/image/export.png);background-repeat: no-repeat;cursor:pointer;color:#C0C0C0;" ></td>
<td style="width:69px"><input type="checkbox" id="chk1" name="chk1" value=" '.$rows["id"].'"/></td>
</tr>';

}
}
?>
</tbody>

<input type="image" name="yousendit" id="yousendit" src="/image/export.png" style="margin:-5px 23px -28px 822px;cursor:pointer;" >

javascript

<script>    
$(document).ready(function() {
$("#yousendit").click(function() {
if(document.getElementById('chk1').checked){
var ms = document.getElementById('chk1').value;

$.ajax({
type:"post",
data:"ms="+ms,
success:function(data) {
window.location = 'billingdatainputandexport/billingdatainputandexportdetailedreport.php?ms='+ms+''
$.post("billingdatainputandexport/billingdatainputandexportdetailedreport.php", { "test": ms } );
$("#result").html(data);
}
});
}
});
});
</script>

最佳答案

您可以更改此设置:

id="chk1"
name="chk1"

<input type="checkbox" id="chk1" name="chk1" value=" '.$rows["id"].'"/>

对此:

class="chk"
name="chk"'.$rows["id"].'

'<input type="checkbox" id="chk1" name="chk"'.$rows["id"].'" value=" '.$rows["id"].'"/>'

并更新 jQuery 代码:

$("#yousendit").click(function() {
var $check = $('.chk:checked');

$.ajax({ //<-------------here you havn't mentioned the url
type:"post",
data:$check.serialize(),
success:function(data){

............

}
});
});

关于javascript - 如何使用 javascript 将选中的复选框值传递到下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21044224/

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