checkbox简单示例

本文详细介绍了Ext JS框架中Form组件的使用,包括Checkbox、Radio、HTML Editor、Date Field、Time Field、Number Field和Trigger Field等基本组件的应用示例。文章还讨论了各组件的关键参数,并提供了多列布局的实现方法。此外,文章还解答了如何在一行中创建多个控件的问题,为读者构建复杂的表单提供了灵感。
鉴于有朋友反应前面的文章过于简单,我决定以后的文章如果没有闪光点就放在新手区(如果不适合,请跟帖),不放在首页!
11.checkbox简单示例
效果图:

js代码:
Ext.onReady(function(){
Ext.QuickTips.init();
var myform=new Ext.FormPanel({
frame:true,
width:330,
layout:"form",
labelWidth:30,
title:"checkbox简单示例",
labelAlign:"left",
renderTo:Ext.getBody(),
items:[{
xtype:"panel",
layout:"column",//也可以是table,实现多列布局
fieldLabel:'爱好',
isFormField:true,//非常重要,否则panel默认不显示fieldLabel
items:[{
columnWidth:.5,//宽度为50%
xtype:"checkbox",
boxLabel:"足球",//显示在复选框右边的文字
name:""
},{
columnWidth:.5,
xtype:"checkbox",
boxLabel:"篮球",
name:""
}]
}]
});
});
关于多列布局,我们可以使用column或者table布局解决!
//其他几个参数
1.checked:true//true则选中,默认为false
2.name:"**"//name值
3.value:""//初始化值,默认为undefine
12.radio简单示例
基本上和checkbox一样,不过注意一组单选框必须name值相同,才能单选。
效果图:

代码:
//基本同上,不做过多解释
Ext.onReady(function(){
Ext.QuickTips.init();
var myform=new Ext.FormPanel({
frame:true,
width:330,
layout:"form",
labelWidth:30,
title:"radio简单示例",
labelAlign:"left",
renderTo:Ext.getBody(),
items:[{
xtype:"panel",
layout:"column",
fieldLabel:'性别',
isFormField:true,
items:[{
columnWidth:.5,
xtype:"radio",
boxLabel:"男",
name:"sex"
//inputValue
},{
columnWidth:.5,
checked:true,
xtype:"radio",
boxLabel:"女",
name:"sex"
}]
}]
});
});
13.htmleditor简单示例
效果图:

js代码:
//基本上同上
Ext.onReady(function(){
Ext.QuickTips.init();
var myform=new Ext.FormPanel({
frame:true,
width:600,
layout:"form",
labelWidth:50,
title:"htmleditor简单示例",
labelAlign:"top",//items中的标签的位置
renderTo:Ext.getBody(),
items:[{
xtype:"htmleditor",
id:"he",
fieldLabel:"编辑器",
anchor:"99%"
}]
});
});
在这里我啰嗦个参数:
//labelAlign参数
labelAlign:此参数是指form表单中items各项的label位置,默认值为left,枚举值有left,right,top
//我看见过有朋友认为此参数指title的位置,是错误的!
几个其他的参数:
//补充几个参数
1.hideLabel:true//默认为false,还适用于有标签的所有表单组件
//下面的一组参数控制编辑器的工具栏选项,都是默认值为true
2.enableColors:true//默认为true,显示字体颜色,字体背景颜色
3.enableAlignments:true//左,中,右对齐
4.enableFont:true//字体
5.enableFontSize:false//字体大小,就是A旁边有个小箭头的
6.enableFormat:false//粗体,斜体,下划线
7.enableLinks:true//链接
8.enableLists:true//列表
9.enableSourceEdit:true//源代码编辑
14.datefield简单示例
效果图:

js代码:
Ext.onReady(function(){
Ext.QuickTips.init();
var myform=new Ext.FormPanel({
frame:true,
width:200,
layout:"form",
labelWidth:30,
title:"dateditor简单示例",
labelAlign:"left",
renderTo:Ext.getBody(),
items:[{
xtype:"datefield",
fieldLabel:"生日",
anchor:"99%"
}]
});
});
15.timefield简单示例
把上面的例子中datefield改为timefield,效果图:

16.numberfield简单示例:
把上面的datefield改为numberfield,就只能输入数字了
17.triggerfield简单示例
说明:它提供了一个触发的事件onTriggerClick,datefield和combox都是继承它
效果图:(点击右边下拉按钮)

js代码:
Ext.onReady(function(){
Ext.QuickTips.init();
var myform=new Ext.FormPanel({
frame:true,
width:200,
layout:"form",
labelWidth:30,
title:"triggerfield简单示例",
labelAlign:"left",
renderTo:Ext.getBody(),
items:[{
xtype:"trigger",
fieldLabel:"触发",
anchor:"99%",
onTriggerClick:function(e){
//在这里写你要实现的事件,很容易扩展
alert("www.langsin.com");
}
}]
});
});
好了,关于form的几个基本组件我们都蜻蜓点水的看了一遍,相信大家感性上知道是怎么回事啦!(总算快写完了formpanel)
前面有朋友说要做个一行多个控件,中间有文字的那种form布局,谢谢支持!
下篇我们就做一个复杂点的form组件,还能提交服务器的综合示例!敬请期待!
在多个开发环境中,`CheckBox`(复选框)是一种常见的用户界面控件,用于让用户选择一个或多个选项。以下是一些主流开发平台中使用 `CheckBox` 的示例代码。 ### Android 平台 在 Android 开发中,可以通过 XML 布局文件定义 `CheckBox`,然后在 Java 或 Kotlin 代码中对其进行操作。 #### 示例:XML 中定义 CheckBox ```xml <CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项" /> ``` #### 示例:Java 中设置监听器和状态 ```java CheckBox checkBox = findViewById(R.id.checkBox); // 设置初始状态为选中 checkBox.setChecked(true); // 获取当前状态并输出 boolean isChecked = checkBox.isChecked(); System.out.println("CheckBox 状态:" + (isChecked ? "已选中" : "未选中")); // 添加点击事件监听 checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> { if (isChecked) { // 被选中时执行的操作 } else { // 取消选中时执行的操作 } }); ``` ### MATLAB 平台 在 MATLAB 的 App Designer 中,可以使用 `CheckBox` 控件来实现交互功能。 #### 示例:根据 CheckBox 状态更新 Edit Field 内容 ```matlab % 在回调函数中获取 CheckBox 的值,并更新 Edit Field value = app.CheckBox.Value; if value == true app.EditField.Value = '10'; else app.EditField.Value = '0'; end ``` ### HTML/JavaScript 平台 在 Web 开发中,可以通过 HTML 定义 `CheckBox`,并通过 JavaScript 进行交互处理。 #### 示例:HTML 中定义 CheckBox ```html <input type="checkbox" id="myCheckbox"> 选项 <p id="status"></p> ``` #### 示例:JavaScript 获取 CheckBox 状态 ```javascript document.getElementById('myCheckbox').addEventListener('change', function() { var status = document.getElementById('status'); if (this.checked) { status.textContent = '选项已选中'; } else { status.textContent = '选项未选中'; } }); ``` ### Windows Forms (.NET) 在 C# 的 Windows Forms 应用程序中,也可以使用 `CheckBox` 来进行简单的状态切换。 #### 示例:C# 获取 CheckBox 状态 ```csharp private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { label1.Text = "已选中"; } else { label1.Text = "未选中"; } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值