启用或禁用复选框时,接收和发送事件的正确方法是什么?
在C#中,我可以轻松地双击,所有代码都将为我完成.但在android中它看起来有点模糊.我想过使用触摸事件处理程序,但如果用户有键盘,它将无法检测到更改,因为它没有触摸.我认为android应该有一个原生事件,用于复选框状态更改.
我有一个这样的视图模型:
public class SignUpViewModel
{
[Required(ErrorMessage = "Bitte lesen und akzeptieren Sie die AGB.")]
[DisplayName("Ich habe die AGB gelesen und akzeptiere diese.")]
public bool AgreesWithTerms { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
视图标记代码:
<%= Html.CheckBoxFor(m => m.AgreesWithTerms) %>
<%= Html.LabelFor(m => m.AgreesWithTerms)%>
Run Code Online (Sandbox Code Playgroud)
结果:
没有执行验证.到目前为止,这没关系,因为bool是一个值类型,永远不会为null.但即使我使AgreesWithTerms可以为空,它也无法工作,因为编译器大喊大叫
"模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式."
那么,处理这个问题的正确方法是什么?
最初我想要一个复选标记,其中文本位于复选标记的左侧.在这个网站上搜索后,我发现最好的解决方法是android:CheckedTextView?但是,我发现用户无法手动更改复选标记.它是按设计的吗?
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/autoupdatecheckboxview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:text="Pop up a message when new data available"
android:typeface="sans" android:textSize="16dip"/>
Run Code Online (Sandbox Code Playgroud) 堆栈上的菜鸟溢出来了.我正在开发一个具有转移工作职能的网页.这允许用户选中复选框以将作业发送回办公室,或从所有可用列表中选择技术人员.我的问题是如何设置复选框,以便在页面加载时默认选中它并相应地禁用选择列表.这是我目前的代码:
<div ng-app="">
Send to Office: <input type="checkbox" ng-model="checked" ng-checked="true"><br/>
<select id="transferTo" ng-disabled="checked">
<option>Tech1</option>
<option>Tech2</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个jsfiddle:http://jsfiddle.net/hugmungus/LvHJw/5/
目前,页面加载并选中复选框,但未禁用列表.如果取消选中然后重新检查,则列表将被禁用.
谢谢您的帮助!
我正在尝试使用jQuery选中(或不选中)复选框.
我的示例HTML:
<input type="checkbox" id="test" name="test" />
Run Code Online (Sandbox Code Playgroud)
尝试清除复选框(不起作用)
$('#test').val('off');
Run Code Online (Sandbox Code Playgroud)
并在检查:
$('#test').val('on');
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery控制复选框?
我想使用request.POST['xzy']列表获取多选复选框的值.这是我的模型和模板代码.
我的模特
class Recommend(models.Model):
user=models.ForeignKey(User)
book=models.ForeignKey(BookModel)
friends=models.ManyToManyField(User, related_name="recommended")
Run Code Online (Sandbox Code Playgroud)
我的模板
{% for friend in friends %}
<input type="checkbox" name="recommendations" id="option{{friend.id}}" value={{friend.username}} />
<label for="option{{friend.id}}"><b>{{friend.username}}</b></label><br />
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我的查看代码
if request.method == 'POST':
recommendations=request.POST['recommendations']
Run Code Online (Sandbox Code Playgroud)
在这里,我希望"推荐"成为包含所有朋友ID的列表,但是这里只是被覆盖并且仅包含在最后一次for循环迭代中分配的值.我怎么解决这个问题.绝望地需要帮助.谢谢.
我将创建一个由jQuery和JSON构建的复选框列表.该列表将是一组可以发送消息的组.它可能是其中一个群体.这部分我可以搞清楚.我遇到的问题是如何启用描述,以便当我单击描述时,选中该复选框.
<div>
<label for="group">
Select lists
</label>
</div>
<div>
<input type="checkbox" name="group" id="group" value="1" title="Main List" />Main List
<input type="checkbox" name="group" id="group" value="2" title="Secondary List" />Secondary List
</div>
Run Code Online (Sandbox Code Playgroud) 我已经查看了有关此问题的不同问题,但由于我的标记限制而无法找到任何可行的问题.
我的标记看起来像是这样(不幸的是,这是由一些后端生成的,我无法更改标记).
<ul>
<li>
<input type="checkbox" value="1" name="test[]" id="myid1">
<label for="myid1">label1</label>
</li>
<li>
<input type="checkbox" value="2" name="test[]" id="myid2">
<label for="myid2">label1</label>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我需要复选框在右侧并垂直居中 <li>
目前,这被设计为:
li input{
display: inline-block;
float: right;
margin-right: 10px;
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用各种值vertical-align,但这似乎没有帮助.此外,在某些情况下,标签可能非常长并且跨越多条线.当li的高度是任意的时,复选框仍然需要能够垂直居中.
我怎样才能实现这一目标?
我是android的新手,我正在尝试为我的应用程序中的所有复选框设置样式.我的应用程序样式设置为Theme.Holo,它是黑暗的,我希望我的列表视图上的复选框是样式Theme.Holo.Light.我不是要创建自定义样式.下面的代码似乎不起作用,根本没有任何事情发生.我需要这样做,因为我的列表视图有一个浅色纸纹理,复选框和复选框文本是白色,我想黑暗.
<style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
<item name="android:checkboxStyle">@style/customCheckBoxStyle</item>
</style>
<style name="customCheckBoxStyle" parent="@android:style/Widget.Holo.Light.CompoundButton.CheckBox">
</style>
Run Code Online (Sandbox Code Playgroud)
如果为应用程序设置样式,还可以将样式设置为单个小部件吗?