我希望能够说:
获取第一个文本块,然后是第一个复选框,其名称中的数字为1.
然后,如果选中该复选框,则可以填充文本块.
看代码:
for (int i = 1; i < 10; i++)
{
TextBlock a = (this.FindName(string.Format("tb_{0}", i)) as TextBlock);
CheckBox b = (this.FindName(string.Format("ck_{0}", i)) as CheckBox);
if (b.IsChecked.HasValue)
{
if (a != null) a.Text = data.ArrayOfSensors[i].ToString();
}
else
{
if (a != null) a.Text = data.ArrayOfSensors[0].ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当启用该复选框时,将使用数组中的索引填充文本块.
非常感谢!
编辑:稍微好一点的解释:
文本块命名为:tb_1,tb_2等
复选框命名为:cb_1,cb_2等
该数组是:
[0] 0
[1] 100
[2] 150
这个数字是他们所有人的共同点.所以我可以使用for循环,将i作为每个的公共变量.我还有大约50个文本框和组合框,并且不想单独写出每个文本框和组合框.
编辑:我的ComboBoxes和Textblocks是在Xaml代码上创建的,如下所示:
<CheckBox x:Name="Cb_1" Width="15" Height="15" Margin="349,53,127,164" IsChecked="True" />
<TextBlock x:Name="tb_1" Text="80" Height="20" Width="20" Margin="266,35,205,177" />
Run Code Online (Sandbox Code Playgroud) 所以我想让下面的代码更紧凑,有没有办法?
也许有一个循环或什么的.尝试了一个for循环,但没有真正解决这个问题......
driver.findElement(By.xpath("//input [@value='1']")).click();
driver.findElement(By.xpath("//input [@value='2']")).click();
driver.findElement(By.xpath("//input [@value='3']")).click();
driver.findElement(By.xpath("//input [@value='4']")).click();
driver.findElement(By.xpath("//input [@value='5']")).click();
driver.findElement(By.xpath("//input [@value='6']")).click();
driver.findElement(By.xpath("//input [@value='7']")).click();
driver.findElement(By.xpath("//input [@value='8']")).click();
driver.findElement(By.xpath("//input [@value='9']")).click();
driver.findElement(By.xpath("//input [@value='10']")).click();
driver.findElement(By.xpath("//input [@value='11']")).click();
driver.findElement(By.xpath("//input [@value='12']")).click();
driver.findElement(By.xpath("//input [@value='13']")).click();
driver.findElement(By.xpath("//input [@value='14']")).click();
driver.findElement(By.xpath("//input [@value='15']")).click();
driver.findElement(By.xpath("//input [@value='16']")).click();
driver.findElement(By.xpath("//input [@value='17']")).click();
driver.findElement(By.xpath("//input [@value='18']")).click();
driver.findElement(By.xpath("//input [@value='19']")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[1]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[2]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[3]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[4]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[5]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[6]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[7]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[8]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[9]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[10]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[11]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[12]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[13]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[14]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[15]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[16]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[17]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[18]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[19]")).click();
driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[20]")).click();
driver.findElement(By.xpath("//button [@type='submit']")).click();
Thread.sleep(10000);
Run Code Online (Sandbox Code Playgroud)
这是带有复选框的两个列表.
我从Controller文件中获取复选框数据,但它没有正确呈现.以下是我的HTML:
HTML:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<table>
<tr ng-repeat="x in People">
<input type="checkbox" id="{{x.id}}" >{{x.name}}<br/>
</tr>
</table>
<button>Click</button>
<script>
//Module Declaration
var app = angular.module('myApp',[]);
//Controller Declaration
app.controller('myCtrl',function($scope){
$scope.People = [
{name:"Peter",id:"201"},
{name:"Lina",id:"202"},
{name:"Roger",id:"203"}
];
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
期望:
3行输入复选框,其名称与它们相邻
结果:
没有JS错误.有人可以帮我解决这个问题吗?
我有很多相同的<div class="checkbox product-option">,每四个div都相互属于.
所以1-4是一组,5-8是一组等.
有没有办法只允许选择组中的1个复选框?
我目前有这个代码,但这适用于所有复选框,而不是一组四个.
jQuery的:
$('input[type="checkbox"]').on('change', function() {
$('input[type="checkbox"]').not(this).prop('checked', false);
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="checkbox product-option">
<label for="addon1">
<span class="product-option-text">
<input class="checkbox-row" type="checkbox" name="addons[1]" id="addon1" onclick="prodconfrecalcsummary()">
<span class="text">Text</span>
</span>
</label>
</div>
<div class="checkbox product-option">
<label for="addon11">
<span class="product-option-text">
<input class="checkbox-row" type="checkbox" name="addons[11]" id="addon1" onclick="prodconfrecalcsummary()">
<span class="text">Text</span>
</span>
</label>
</div>
<div class="checkbox product-option">
<label for="addon12">
<span class="product-option-text">
<input class="checkbox-row" type="checkbox" name="addons[21]" id="addon1" onclick="prodconfrecalcsummary()">
<span class="text">Text</span>
</span>
</label>
</div>
<div class="checkbox product-option">
<label for="addon54">
<span class="product-option-text">
<input class="checkbox-row" type="checkbox" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在表单中呈现一个复选框,但得到了下一个错误:
Form.php第1149行中的TransformationFailedException:无法转换属性路径"[active]"的值:预期为布尔值.
是的,我发送的是一个0或1的整数,但是twig将它们作为字符串获取它有意义,但我真的找不到如何渲染复选框.
这是控制器:
$form = $form->add('active', 'checkbox', array('label' => 'User active?','required' => false));
Run Code Online (Sandbox Code Playgroud)
这是Twig方面:
{{ form_widget(form.active, { attr: { 'class': 'form-control' }}) }}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我使用iCheck复选框和下面的复选框选择html,
<input type="checkbox" name="allDay" id="allDay" class="icheck" data-checkbox="icheckbox_minimal-red" value="true"> All day event</label>
Run Code Online (Sandbox Code Playgroud)
我正在使用Ajax提交表单,但没有使用.serialize()函数,我正在进行单独的表单输入.val(),然后对条目进行一些操作,然后在形式ajax数据中作为变量传递,
现在我想为复选框传递值,如果它被选中,否则它不应传递任何值,
我有以下代码为变量取值,
allDay = $('#allDay').val();
Run Code Online (Sandbox Code Playgroud)
但有了这个,它总是传递值= true,即使它checked或者unchecked.
如果选中复选框,我怎样才能将复选框的值传递给变量?
谢谢,
我想使用单击按钮在选择特定div /表中的所有复选框和取消选中所有复选框之间切换.此外,我希望链接/或按钮将名称更改为"全选"和"取消全选".我已经看到类似的答案使用复选框或两个不同的按钮点击,但没有这个.我会使用jquery保持简单和简短.
HTML
<body>
<div id="main">
<div id="first">
<h1>Check & Uncheck All Options</h1>
<p>Check & Uncheck All Options by Button</p>
<input id="checkAll" type="button" value="Check/Uncheck All ">
<div class="button">
<input class="first" id="Item 1" name="option1" type="checkbox">
<label class="label1" for="Item 1">Item 1</label>
<input class="first" id="Item 2" name="option1" type="checkbox">
<label class="label1" for="Item 2">Item 2</label>
<input class="first" id="Item 3" name="option1" type="checkbox">
<label class="label1" for="Item 3">Item 3</label>
<input class="first" id="Item 4" name="option1" type="checkbox">
<label class="label1" for="Item 4">Item 4</label>
</div>
</body>Run Code Online (Sandbox Code Playgroud)
我是Android开发的新手,我创建了一个复选框以及如何使用共享首选项保存选中/取消选中
final Button add = (Button) findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
addNewBubble();
add.setEnabled(false);
}
});
CheckBox checkBox = (CheckBox)findViewById(R.id.add_fb);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isCheckedValue = isChecked;
}
});
}
private void addNewBubble() {
BubbleLayout bubbleView = (BubbleLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.bubble_layout, null);
bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() {
@Override
public void onBubbleRemoved(BubbleLayout bubble) {
finish();
System.exit(0);
}
});
bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() {
@Override
public void onBubbleClick(BubbleLayout bubble) {
Intent in = new Intent(MainActivity.this, PopUpWindow.class);
in.putExtra("yourBoolName", isCheckedValue ); …Run Code Online (Sandbox Code Playgroud) checkbox android sharedpreferences android-checkbox android-studio
我想知道如何在react-native中选中和取消选中复选框?
我需要使用getInitialState和props吗?还是只需要使用复选框和onPress?
我目前将数据保存到mongo中以选择问题,并标记正确的答案。在mongo中,我将它们保存为question.options.option1.check =“ on”之类的正确答案。
当我进入“编辑”页面时,我从mongo中提取了特定的记录,该记录在ejs中可以作为“问题”使用,并且我能够轻松地将可编辑字段的值填充为question.question或question.options.option1.text等。但是,我也想标记以前已选中的复选框。以下是该复选框的示例。
<input id=opt1 type="checkbox" name="check1" >
Run Code Online (Sandbox Code Playgroud)
当我使用
<input id=opt1 type="checkbox" name="check1" <%=question.options.option1.check%> >它不起作用时,我也尝试过<input id=opt1 type="checkbox" name="check1" checked="<%=question.options.option1.check%>">这也不起作用。但是,如果我给属性“ checked” =“此处有任何值或根本没有任何值”,它将进行检查,这是错误的。
因此,问题是在编辑页面上检查相应复选框的正确方法是什么?