jquery

$("input[type=radio][name=userName][value=2]").attr("checked",true);
$("#aa").html("sdsds");
$("#a")[0].innerHTML="aaa";
得到下拉列表text: $("#select1").find("option:selected").text();
得到單選按鈕值:j_radio = $("input[name='radioName']:checked").val();
$("#labelID")[0].innerHTML="";

$('.ck_box').bind('click',function(){});
$("input[name='ck_box']").bind("propertychange", function(){});
$("#ck_box").bind("propertychange", function(){})


Jquery操作select:

//得到select項的個數
jQuery.fn.size = function(){
return jQuery(this).get(0).options.length;
}

//獲得選中項的索引
jQuery.fn.getSelectedIndex = function(){
return jQuery(this).get(0).selectedIndex;
}

//獲得當前選中項的文本
jQuery.fn.getSelectedText = function(){
if(this.size() == 0) return "下拉框中無選項";
else{
var index = this.getSelectedIndex();
return jQuery(this).get(0).options[index].text;
}
}

//獲得當前選中項的值
jQuery.fn.getSelectedValue = function(){
if(this.size() == 0)
return "下拉框中無選中值";

else
return jQuery(this).val();
}

//設置select中值爲value的項爲選中
jQuery.fn.setSelectedValue = function(value){
jQuery(this).get(0).value = value;
}

//設置select中文本爲text的第一項被選中
jQuery.fn.setSelectedText = function(text)
{
var isExist = false;
var count = this.size();
for(var i=0;i<count;i++)
{
if(jQuery(this).get(0).options[i].text == text)
{
jQuery(this).get(0).options[i].selected = true;
isExist = true;
break;
}
}
if(!isExist)
{
alert("下拉框中不存在該項");
}
}
//設置選中指定索引項
jQuery.fn.setSelectedIndex = function(index)
{
var count = this.size();
if(index >= count || index < 0)
{
alert("選中項索引超出範圍");
}
else
{
jQuery(this).get(0).selectedIndex = index;
}
}
//判斷select項中是否存在值爲value的項
jQuery.fn.isExistItem = function(value)
{
var isExist = false;
var count = this.size();
for(var i=0;i<count;i++)
{
if(jQuery(this).get(0).options[i].value == value)
{
isExist = true;
break;
}
}
return isExist;
}
//向select中添加一項,顯示內容爲text,值爲value,如果該項值已存在,則提示
jQuery.fn.addOption = function(text,value)
{
if(this.isExistItem(value))
{
alert("待添加項的值已存在");
}
else
{
jQuery(this).get(0).options.add(new Option(text,value));
}
}
//刪除select中值爲value的項,如果該項不存在,則提示
jQuery.fn.removeItem = function(value)
{
if(this.isExistItem(value))
{
var count = this.size();
for(var i=0;i<count;i++)
{
if(jQuery(this).get(0).options[i].value == value)
{
jQuery(this).get(0).remove(i);
break;
}
}
}
else
{
alert("待刪除的項不存在!");
}
}
//刪除select中指定索引的項
jQuery.fn.removeIndex = function(index)
{
var count = this.size();
if(index >= count || index < 0)
{
alert("待刪除項索引超出範圍");
}
else
{
jQuery(this).get(0).remove(index);
}
}
//刪除select中選定的項
jQuery.fn.removeSelected = function()
{
var index = this.getSelectedIndex();
this.removeIndex(index);
}
//清除select中的所有項
jQuery.fn.clearAll = function()
{
jQuery(this).get(0).options.length = 0;
}





/**取消checkbox欄位選取*/$#news_top.attr"checked",false;$#news_top.attr"checked","";/**判斷checkbox是否選取*/if$"#news_top".attr'checked'==undefined/**全選checkbox欄位,或者反向選取*/$"#clickAll".clickfunction{$"input[@name='news_top']".eachfunction{if$this.attr"checked"{$this.attr"checked",false;}else{$this.attr"checked",true;}};};/**checkbox的value值*/$'input[@name="news_top"][@checked]'.val;

== 獲取一組radio被選中項的值 $("input[name='requestStatus']:checked").val();

jquery取得text,areatext,radio,checkbox,select的值,以及其他一些操作;1.假如我們有如下頁面

獲取一組radio被選中項的值$("input[name='requestStatus']:checked").val();HTML代碼:select
option value="1"Flowers/option option
value="2"selected="selected"Gardens/option option
value="3"Trees/option/select jQuery代碼:$("select
option:selected")結果:[option
value="2"selected="selected"Gardens/option]所以要取得選中值(value)可以這樣:$("select
option:selected").val()//對應上例的結果是:2取得選中的文本:$("select
option:selected").text()//對應上例的結果是:Gardens JQuery獲取和設置Select選項 獲取Select:

獲取select選中的text: $("#ddlRegType").find("option:selected").text();

獲取select選中的value: $("#ddlRegType").val(); 獲取select選中的索引:

$("#ddlRegType").get(0).selectedIndex; 設置select: 設置select選中的索引:

$("#ddlRegType").get(0).selectedIndex=index;//index爲索引值

設置select選中的value: $("#ddlRegType").attr("value","Normal");

$("#ddlRegType").val("Normal"); $("#ddlRegType").get(0).value=value;

設置select選中的text: var count=$("#ddlRegType").size(); for(var i=0;i
count;i++){if($("#ddlRegType").get(0).options[i].text==text){$("#ddlRegType").get(0).options[i].selected=true;break;}}

清空Select: $("#ddlRegType").empty(); ===

在進行判斷頁面中的一組Radio是否選中與否的時候需要注意的是必須聲明一個變量來進行判斷而不能直接進行判斷,如下所示: var
item=$(":radio:checked");var len=item.length; if(len 0){}//這是重點

注意這種寫法是在firefox下才有的。這可能是firefox下的一個bug。

而得到一組Radio中的選中項的是:$(":radio:checked").val() == script
language="javascript"!--$(function(){var
input=$("#appDIV").find("input[type='radio']");input.attr("disabled","disabled");//input.eq(1).attr("checked",true);input.each(function(){if($(this).val()==2){$(this).attr("checked",true);}});});//--/script用div將三個radio套着!div
id="appDIV"style="width:500px;margin:0 auto;"input
type="radio"value="1"/input type="radio"value="2"/input
type="radio"value="3"//div ==

/*把select元件都歸到選第一項*/$(this)[0].selectedIndex=0; function
CheckEmpty(){var item=$("input[name='RadioButtonList1']:checked");var
len=item.length;//if(len
0)if(item.attr('checked')==undefined){$('#RadioButtonList1_1').parent().find(".formtips").remove();var
errorMsg='請選擇性別.';$('#RadioButtonList1_1').parent().append('span
class="formtips onError"'+errorMsg+'/span');

}else{$('#RadioButtonList1_1').parent().find(".formtips").remove();var
okMsg='輸入正確.';$('#RadioButtonList1_1').parent().append('span
class="formtips onSuccess"'+okMsg+'/span');}//return bool;}
Jquery radio/select選中問題2010-01-02

19:08/**取消checkbox欄位選取*/$#news_top.attr"checked",false;

$#news_top.attr"checked","";

/**判斷checkbox是否選取*/if$"#news_top".attr'checked'==undefined/**全選checkbox欄位,或者反向選取*/$"#clickAll".clickfunction{

$"input[@name='news_top']".eachfunction{
if$this.attr"checked"{
$this.attr"checked",false;

} else{
$this.attr"checked",true;
}
} ;
} ;

/**checkbox的value值*/$'input[@name="news_top"][@checked]'.val;

== 獲取一組radio被選中項的值 $("input[name='requestStatus']:checked").val();


jquery取得text,areatext,radio,checkbox,select的值,以及其他一些操作;

1.假如我們有如下頁面

獲取一組radio被選中項的值$("input[name='requestStatus']:checked").val();

HTML代碼:select

option value="1"Flowers/option option

value="2"selected="selected"Gardens/option option

value="3"Trees/option/select jQuery代碼:$("select
option:selected")結果:[option

value="2"selected="selected"Gardens/option]所以要取得選中值(value)可以這樣:$("select
option:selected").val()//對應上例的結果是:2取得選中的文本:$("select

option:selected").text()//對應上例的結果是:Gardens JQuery獲取和設置Select選項 獲取Select:
獲取select選中的text: $("#ddlRegType").find("option:selected").text();
獲取select選中的value: $("#ddlRegType").val(); 獲取select選中的索引:
$("#ddlRegType").get(0).selectedIndex; 設置select: 設置select選中的索引:
$("#ddlRegType").get(0).selectedIndex=index;//index爲索引值
設置select選中的value: $("#ddlRegType").attr("value","Normal");
$("#ddlRegType").val("Normal"); $("#ddlRegType").get(0).value=value;
設置select選中的text: var count=$("#ddlRegType").size(); for(var i=0;i
count;i++){if($("#ddlRegType").get(0).options[i].text==text){$("#ddlRegType").get(0).options[i].selected=true;break;}}
清空Select: $("#ddlRegType").empty(); ===
在進行判斷頁面中的一組Radio是否選中與否的時候需要注意的是必須聲明一個變量來進行判斷而不能直接進行判斷,如下所示: var
item=$(":radio:checked");var len=item.length; if(len 0){}//這是重點
注意這種寫法是在firefox下才有的。這可能是firefox下的一個bug。
而得到一組Radio中的選中項的是:$(":radio:checked").val() == script
language="javascript"!--$(function(){var
input=$("#appDIV").find("input[type='radio']");input.attr("disabled","disabled");//input.eq(1).attr("checked",true);input.each(function(){if($(this).val()==2){$(this).attr("checked",true);}});});//--/script用div將三個radio套着!div
id="appDIV"style="width:500px;

margin:0 auto;

"input
type="radio"value="1"/input type="radio"value="2"/input
type="radio"value="3"//div ==
/*把select元件都歸到選第一項*/$(this)[0].selectedIndex=0; function
CheckEmpty(){var item=$("input[name='RadioButtonList1']:checked");var
len=item.length;//if(len
0)if(item.attr('checked')==undefined){$('#RadioButtonList1_1').parent().find(".formtips").remove();var
errorMsg='請選擇性別.';$('#RadioButtonList1_1').parent().append('span
class="formtips onError"'+errorMsg+'/span');
}else{$('#RadioButtonList1_1').parent().find(".formtips").remove();var
okMsg='輸入正確.';$('#RadioButtonList1_1').parent().append('span
class="formtips onSuccess"'+okMsg+'/span');

} //return bool;}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章