如何使用javascript或jquery检查复选框? [英] how to check a check box using javascript or jquery?

查看:63
本文介绍了如何使用javascript或jquery检查复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI出口





i我在java脚本中遇到困难,我没有得到如何继续解决这个问题



我的问题是



i有表格,我有国家代码,简短国家代码和复选框







HI Exports


i am facing difficult in the java-script,i am not getting how to carry on with this problem

my problem is

i have form where i am having country code , short country code , and check box


like

countryCode shortcountrycode    check box

  1                  USD
  2                  INR
  3                  USD





现在,如果我选中了1号复选框,那么java脚本应该是像它的工作应该自动检查第3个复选框,因为NO 1和第3个Checkbox shortcountrycode是相同的(USD)。



复选框是动态生成的



如何实现它请帮帮我



now if i checked the no 1 check box the java-script should work like it should automatically check the 3rd check box because NO 1 and 3rd Checkbox shortcountrycode is same (USD).

Check-Box are generated dynamically

how to achieve it please help me

推荐答案

在js上查看此示例小提琴。但我没有检查任何条件。正如您所提到的,您可以使用复选框ID设置它,如果它不是动态的



http://jsfiddle.net/xjn3Q/65/ [ ^ ]
See this example on jsfiddle. But I didn't check any condition. As you mentioned you can set it by using the checkbox id, If it is not dynamic

http://jsfiddle.net/xjn3Q/65/[^]


您应该为每个复选框指定与其shortcountrycode相关的属性。例如:

You should give each checkbox a property relating to its shortcountrycode. For instance:
<input type="checkbox" name="country" value="1" data-code="USD"></input>





然后使用jQuery为任何已检查的框设置一个事件处理程序:



Then set an event handler with jQuery for any box that's checked:


(function(){
(function() {


这篇关于如何使用javascript或jquery检查复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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