<input id="myCheckbox" type="checkbox" /> Please, please check me
<input id="myRadio" type="radio" /> Am I selected ?
Run Code Online (Sandbox Code Playgroud)
我想要以下行为:
我将如何以一种非常简单的方式做到这一点?
提前感谢您的回应.
如果我有一些单选按钮:
<input type="radio" name="test" value="apple"> Apple<br/>
<input type="radio" name="test" value="banana" CHECKED> Banana<br/>
<input type="radio" name="test" value="carrot"> Carrot<br/>
Run Code Online (Sandbox Code Playgroud)
然后我用jQuery定义了无线电组
var test = $('input:radio[name="test"]')
Run Code Online (Sandbox Code Playgroud)
如何在不重写的情况下基于变量test获取checked元素的值
var test_val = $('input:radio[name="test"]:checked').val();
Run Code Online (Sandbox Code Playgroud)
我试过了两个
$(test):checked.val();
test:checked.val();
Run Code Online (Sandbox Code Playgroud)
作为变更函数的一部分,我也试过这个:
$(test).change(function() {
if ($(this):checked.val() == 'no') {
$('#featured').stop().fadeOut();
} else if ($(this):checked.val() == 'yes') {
$('#featured').stop().fadeIn();
}
});
Run Code Online (Sandbox Code Playgroud)
只是想知道这是否可行,或者我是否必须重新写出完整的输入选择器来获取值.
PS
如果IE8不支持:checked选择器,我可以使用什么?
该应用程序是一个步进音序器应用程序,具有16个无线电组,每组有8个按钮.除非我使用我创建的清除按钮清除所有放射线组,否则除非一个组选择了一个按钮,否则它可以完美地工作.我想要添加的是一些代码,表示当再次选择所选单选按钮时,它会像切换一样关闭.我尝试使用切换,但随后出现了其他问题.下面是对它的一次尝试但是我猜测它是不合适的
final RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.RadioGroup1);
RadioButton lC1 = (RadioButton)findViewById(R.id.RadioButtonlowC1);
Button D1 = (Button)findViewById(R.id.RadioButtonD1);
D1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PdBase.sendFloat("D1", 74);
int selectedTypeId = radioGroup1.getCheckedRadioButtonId();
RadioButton D1 = (RadioButton) findViewById(selectedTypeId);
if(radioGroup1 != null) // This will be null if none of the radio buttons are selected
radioGroup1.clearCheck();
PdBase.sendFloat("D1", 0);
}
});
Run Code Online (Sandbox Code Playgroud) 是否有可能(在C#中)使checked(...)表达式具有动态"范围"以进行溢出检查?换句话说,在以下示例中:
int add(int a, int b)
{
return a + b;
}
void test()
{
int max = int.MaxValue;
int with_call = checked(add(max, 1)); // does NOT cause OverflowException
int without_call = checked(max + 1); // DOES cause OverflowException
}
Run Code Online (Sandbox Code Playgroud)
因为在表达式中checked(add(max, 1)),函数调用会导致溢出,而不会OverflowException抛出,即使在表达式的动态范围内存在溢出checked(...).
有没有办法让两种方式评估int.MaxValue + 1投掷OverflowException?
编辑:嗯,要么告诉我是否有办法,或者给我一个更好的方法来做到这一点(请).
我认为我需要这个的原因是因为我的代码如下:
void do_op(int a, int b, Action<int, int> forSmallInts, Action<long, long> forBigInts)
{
try
{
checked(forSmallInts(a, b));
} …Run Code Online (Sandbox Code Playgroud) 我是JavaScript的初学者.我的动态页面上有几个单选按钮,我想创建一个脚本来进行以下操作:
HTML:
<input type="radio" id="elemainfoto">
<input type="radio" id="elemainfoto">
<input type="radio" id="elemainfoto">
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var radio = '#elemainfoto',
if(radd.value == 0) {
radd.checked the first radio element,
} else {
keep the way it is,
}
Run Code Online (Sandbox Code Playgroud)
如果没有标记任何无线电元素,则标记第一个必须的.
在asp.net Webforms 中,我有一个CheckBox和Button。
<asp:CheckBox ID="checkBox" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Check" OnClick="Button1_Click"/>
Run Code Online (Sandbox Code Playgroud)
我想用Checkbox来处理检查状态ButtonClick。但它只是获得了错误的价值。
if (checkBox.Checked == (true))
{
Label1.Text = "Selected";
}
else
{
Label1.Text = "Not Selected";
}
Run Code Online (Sandbox Code Playgroud)
每次之后click我都会在我的Label. 我认为这是很基本的,但现在我无法解决。
有没有什么办法解决这一问题。
嗨,这可能是一个非常新手的问题,但这是我的问题。我有代表一周中所有日子的复选框。如果检查了一天,我想将它添加到一个数组中,以便在提交时我可以将数组传递给后端。我从引导程序复制了复选框结构开始。我尝试添加逻辑以查看是否选中了一个框,如果选中了我想将它推送到我的空数组状态。此外,如果选中了复选框但未选中,我想从状态数组中删除该项目。到目前为止,我还没有找到使这一切正常的方法。
import React from 'react'
class CalenderSettingsModal extends React.Component {
constructor(props) {
super(props);
this.state={
workStart: 8,
workEnd: '',
workDays:[],
}
handleCheckboxChange = (event)=> this.setState({workDays: event.target.value});
}
render() {
return (
<React.Fragment>
<form>
<div>
<h5>Select your workday(s):</h5>
<div class="custom-control custom-checkbox " >
<input type="checkbox" class="custom-control-input" id="monday" value="monday" onChange={this.handleCheckboxChange}/>
<label class="custom-control-label" for="monday">Monday</label>
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="tuesday" value="tuesday" onChange={ this.handleCheckboxChange}/>
<label class="custom-control-label" for="tuesday">Tuesday</label>
</div>
</form>
<button >Save settings</button>
</React.Fragment>
);
}
}
export default CalenderSettingsModal;
Run Code Online (Sandbox Code Playgroud)
到目前为止,我尝试在复选框被选中但不起作用时完成将值分配给 workDays,我不确定如何完成我想做的事情。任何见解将不胜感激。
我正在尝试为复选框设置自定义验证.我有7个复选框,每个复选框都有相同的名称,我想确定是否检查了最后一个.这是我的代码,我知道它的错误,任何人都可以了解如何正确地堆叠:last和:checked selectors在一起?
$.validator.addMethod('ObserverOtherBox',function(v, e) {
return ($('[[name="4_observers"]:last]:checked').length == 1) && ($('[name="4_observerstxt"]').length == 0) ;
}, 'Please enter the other observers');
Run Code Online (Sandbox Code Playgroud) 单击/选中复选框时,我无法触发简单的警报.我一直在挠头,想知道为什么我不能让它工作,我知道它会变得简单......那么,我做错了什么?
<script type="text/javascript">
$('#test1').click(function(){
alert('clicked');
});
</script>
<input type="checkbox" id="test1" value="test1" name="test1" value="-1">test1</input>
Run Code Online (Sandbox Code Playgroud) 嗨,我想在我点击带文字的div时勾选或取消选中复选框.使用jquery 1.9.1这里是js小提琴的链接
<div class="tel_show">
<input type="checkbox" name="whatever" />
visible
</div>
$("div.tel_show").live("click",function(event) {
var target = $(event.target);
if (target.is('input:checkbox')) return;
var checkbox = $(this).find("input[type='checkbox']");
if( checkbox.attr("checked") == "" ){
checkbox.attr("checked","true");
} else {
checkbox.attr("checked","");
}
});
Run Code Online (Sandbox Code Playgroud)
checked ×10
checkbox ×7
jquery ×5
javascript ×3
c# ×2
radio-button ×2
alert ×1
android ×1
asp.net ×1
click ×1
if-statement ×1
radio ×1
reactjs ×1
scope ×1
triggers ×1
uncheck ×1
unchecked ×1
validation ×1