select与radio
select标签的处理
html代码
<select class="form-control" id="role" name="user.role">
<option value="0">教师</option>
<option value="1">学生</option>
</select>
显示下拉框的对应的值
$("#role option[value='"+d.role+"']").attr("selected","selected");
最近(2019.11.20)发现一种新的方法用来设置下拉框选中的值
$("#uScreenType option[value='"+obj.type+"']").prop("selected",true);
上面代码中,d表示返回对象,d.role表示获取对象的属性值
获取下拉框的值
var role = $("#role option:selected").val();
radio标签的处理
html代码
<div>
<input type="radio" name="infotime" value="con" /><span>手动发布</span>
<input type="radio" name="infotime" value="autoafterclass" checked="checked"/><span>课间自动发布</span>
<input type="radio" name="infotime" value="autoinclass" /><span>上课自动发布</span>
</div>
显示单选的值
$("input:radio[value='"+o.data.infotype+"']").attr("checked","checked");
上面中o.data.infotype表示单选框的值
或者表示为
$("input:radio[value='"con"']").attr("checked","checked");
获取radio的值
获取单选框的值
var tempValue = $('input[name="infotime"]:checked').val();
通过ID设置背景色,字体颜色、字体大小
//设置背景色
var textcolorbackValue = $("#textcolorback").val();
$("#text").css("background-color","#"+textcolorbackValue);
//设置字体的大小
var textsizeValue = $("#textsize").val()+"px";
$("#text").css("font-size",textsizeValue);
//设置字体颜色
var textcolorValue = $("#textcolor").val();
$("#text").css("color","#"+textcolorValue);
注意上述代码中ID为text的,为显示字体内容的位置
设置按钮的隐藏与显示
html代码
<button id="updateBtn" class="btn btn-default">修改</button>
js代码
//js设置显示
$("#updateBtn").css("display","block");
//js设置隐藏
$("#updateBtn").css("display","none");