如何在ASP.NET中的javascript中获取所选按钮值 [英] How to get the selected button values in javascript in ASP.NET

查看:61
本文介绍了如何在ASP.NET中的javascript中获取所选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮。它绑定数据库中的数据。



例如它有30个按钮,如1,2,3 ..... 30.



当用户选择4按钮意味着值应该是这样的25,27,24,22。



如何发生这种情况。



我尝试过:



我尝试使用标签,但它只显示一个值



用户单击下一个按钮表示仅显示按钮值。

I have a button .it is bind the data from database.

For example it has 30buttons the values like 1,2,3.....30.

when a user select 4buttons means the values should be like this 25,27,24,22.

How this things can happen.

What I have tried:

I tried with a label but it shows only one value

The user click the next button means that button value only shown.

推荐答案

您可以使用jquery获取所有选中的复选框和相关值,



you can use the jquery to get all the selected checkboxes and the associated values,

<pre>function getValueUsingClass(){
	/* declare an checkbox array */
	var chkArray = [];
	
	/* look for all checkboes that have a class 'chk' attached to it and check if it was checked */


。chk:选中)。each( function (){
chkArray.push(
(".chk:checked").each(function() { chkArray.push(


this )。val());
});

/ * 我们加入以逗号分隔的数组* / $ b已选择$ b var ;
selected = chkArray.join(' ,')+ ;

/ * 检查是否有选中的复选框,默认长度为1,因为它包含一个逗号* /
如果(selected.length> 1 ) {
alert( 您已选择 + selected);
} else {
alert( 请至少选中一个复选框);
}
}
(this).val()); }); /* we join the array separated by the comma */ var selected; selected = chkArray.join(',') + ","; /* check if there is selected checkboxes, by default the length is 1 as it contains one single comma */ if(selected.length > 1){ alert("You have selected " + selected); }else{ alert("Please at least one of the checkbox"); } }


这篇关于如何在ASP.NET中的javascript中获取所选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆