在本文中,我们将给您介绍关于取消选择期间未触发jQuery$的详细内容,并且为您解答“#radioButton”。change的相关问题,此外,我们还将为您提供关于Android–RadioButto
在本文中,我们将给您介绍关于取消选择期间未触发jQuery $的详细内容,并且为您解答“#radioButton”。change的相关问题,此外,我们还将为您提供关于Android – RadioButton未取消选中初始检查状态、android – 取消选中RadioButton的 – 替代方法、Android:如何在Java中以编程方式检查/取消选中RadioGroup中的RadioButton、ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList_jquery的知识。
本文目录一览:- 取消选择期间未触发jQuery $(“#radioButton”)。change(…)(取消选择是什么)
- Android – RadioButton未取消选中初始检查状态
- android – 取消选中RadioButton的 – 替代方法
- Android:如何在Java中以编程方式检查/取消选中RadioGroup中的RadioButton
- ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList_jquery
取消选择期间未触发jQuery $(“#radioButton”)。change(…)(取消选择是什么)
大约一个月前,米特的问题没有得到解答。可悲的是,我现在遇到了同样的情况。
情况如下:我正在使用jQuery捕获单选按钮中的更改。选择单选按钮后,我将启用一个编辑框。当取消选择单选按钮时,我希望禁用编辑框。
使能的作品。当我在组中选择其他单选按钮时, 不会 触发该change
事件。有谁知道如何解决这一问题? __
<input type="radio" id="r1" name="someRadioGroup"/><script type="text/javascript"> $("#r1").change(function () { if ($("#r1").attr("checked")) { $(''#r1edit:input'').removeAttr(''disabled''); } else { $(''#r1edit:input'').attr(''disabled'', true); } });</script>
答案1
小编典典看起来该change()
函数仅在您选中单选按钮时才调用,而不是在取消选中它时才调用。我使用的解决方案是将change事件绑定到每个单选按钮:
$("#r1, #r2, #r3").change(function () {
或者,您可以为所有单选按钮赋予相同的名称:
$("input[name=someRadioGroup]:radio").change(function () {
Android – RadioButton未取消选中初始检查状态
我在RadioGroup中有一个RadioButton,
当我设置按钮的初始状态时出现问题
android:checked = “true”
因为如果我按下RadioButton“F”,则RadioButton“M”不会取消选中…
我能怎么做?怎么了?
这是代码:
<RadioGroup
android:id="@+id/registrazione_utente_sesso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="M"
android:textColor="#ff7415"
android:textSize="18sp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13.33dp"
android:text="F"
android:textColor="#ff7415"
android:textSize="18sp" />
</RadioGroup>
屏幕:
初始状态(正确):
http://i.imgur.com/YsUIg.png
按下RadioButton“F”的最终状态(错误):
http://i.imgur.com/YJms9.png
谢谢
解决方法:
使用android:id为单选按钮分配一个唯一的id,然后设置RadioGroup的android:checkedButton属性,如下所示:
<RadioGroup
android:id="@+id/registrazione_utente_sesso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/radiobutton_m" >
<RadioButton
android:id="@+id/radiobutton_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textColor="#ff7415"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radiobutton_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13.33dp"
android:text="F"
android:textColor="#ff7415"
android:textSize="18sp" />
</RadioGroup>
android – 取消选中RadioButton的 – 替代方法
解决方法
RadioGroup radioGroup; RadioButton radioButton1; RadioButton radioButton2; RadioButton radioButton3; boolean hack = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); radioGroup = (RadioGroup) findViewById(R.id.rg); radioButton1 = (RadioButton) findViewById(R.id.r1); radioButton2 = (RadioButton) findViewById(R.id.r2); radioButton3 = (RadioButton) findViewById(R.id.r3); OnClickListener radioClickListener = new OnClickListener() { public void onClick(View v) { if (v.getId() == radioGroup.getCheckedRadioButtonId() && hack) { radioGroup.clearCheck(); } else { hack = true; } } }; OnCheckedchangelistener radioCheckchangelistener = new OnCheckedchangelistener() { @Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { hack = false; } }; radioButton1.setonCheckedchangelistener(radioCheckchangelistener); radioButton2.setonCheckedchangelistener(radioCheckchangelistener); radioButton3.setonCheckedchangelistener(radioCheckchangelistener); radioButton1.setonClickListener(radioClickListener); radioButton2.setonClickListener(radioClickListener); radioButton3.setonClickListener(radioClickListener); }
好的,现在我已经更新了.这应该是Philipz
Android:如何在Java中以编程方式检查/取消选中RadioGroup中的RadioButton
settingsActivity:
在这里,我有一个TextView(称为“settings2”)作为一种变量和我的三个RadioButtons(radio0,radio1和radio2),它们在RadioGroup中.
切换到MainActivity后,如果上次检查radio0,我的程序会在文件中保存“0”(保存在SD卡上).但是如果上次检查了radio1,它会在该文件中放置1.如果上次检查了radio2,它会在该文件中放入2.
我在onPause方法中使用了这个.
然后在onResume方法中,我读取该文件的文本并将其放在TextView“settings2”中.
在此代码之后(仍在onResume中)我想检查/取消选中我的RadioButtons.因此,如果TextView“settings2”的文本为“0”,则应检查RadioButton“radio0”而不检查其他.如果此TextView的文本为“1”,则应检查RadioButton“radio1”而不检查其他.如果此TextView的文本为“2”,则应检查RadioButton“radio2”而不检查其他.
为此,我使用了以下两个代码但不幸的是它们没有用.
第一个代码:
if (settings2.getText().equals("0")) { radio0.setChecked(true); radio1.setChecked(false); radio2.setChecked(false); } else if (settings2.getText().equals("1")) { radio0.setChecked(false); radio1.setChecked(true); radio2.setChecked(false); } else if (settings2.getText().equals("2")) { radio0.setChecked(false); radio1.setChecked(false); radio2.setChecked(true); }
第二个代码:
if (settings2.getText().equals("0")) { radioGroup1.check(R.id.radio0); } else if (settings2.getText().equals("1")) { radioGroup1.check(R.id.radio1); } else if (settings2.getText().equals("2")) { radioGroup1.check(R.id.radio2); }
有人可以帮忙解决这个小问题吗?我期待着你的帮助!
提前致谢!
解决方法
EditText et = .... et.getText() // Does not return a string,it returns an Editable.
尝试:
String str = et.getText().toString;
然后使用str进行比较.
编辑:请参阅下面的源代码,了解为什么必须使用字符串进行比较.默认值是通过引用进行比较,但字符串具有覆盖等于基于字符串值进行比较.如果您不使用String,则不会获得匹配.
public boolean More ...equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { String anotherString = (String)anObject; int n = count; if (n == anotherString.count) { char v1[] = value; char v2[] = anotherString.value; int i = offset; int j = anotherString.offset; while (n-- != 0) { if (v1[i++] != v2[j++]) return false; } return true; } } return false; }
ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList_jquery
界面代码:
脚本代码: