radio
$("input[name=' ']").each(function(){
if($(this).val()==""){
$(this).attr("checked",true);
}
});select, 选中值为aa的选项
$("# ").val("aa");根据text值设置选中项
一、$(".selector").find("option[text='pxx']").attr("selected",true);
二、<pre class="prettyprint lang-js" style="margin-top: 1em; margin-bottom: 1em; padding: 0px 1em; font-family: 宋体; line-height: 21.6px; width: 600px; border-left: 3px solid rgb(204, 204, 204); overflow-x: auto; font-size: 9pt !important; color: rgb(0, 112, 166) !important;">var VZhi=$("#TZhi").val();
$("#S1 option").each(function(i,n){
if($(n).text()==VZhi){
$(n).attr("selected",true);
}
});获取当前选中项的value
$(".selector").val();获取当前选中项的text
$(".selector").find("option:selected").text();select联动
$(".selector1").change(function(){
// 先清空第二个
$(".selector2").empty();
// 实际的应用中,这里的option一般都是用循环生成多个了
var option = $("<option>").val(1).text("pxx");
$(".selector2").append(option);
});
本文介绍了使用jQuery来操作HTML中的Select和Radio元素的方法。包括如何设置和获取Select的选中项,如何根据值或文本选择选项,以及如何处理Radio元素的选择状态。还提供了联动Select元素的示例。

489

被折叠的 条评论
为什么被折叠?



