//文本框,文本區域:
textbox:
var str = $('#txt').val();
$('#txt').val("Set Lbl Value");
$("#text_id").attr("value",'');//清空內容
$("#text_id").attr("value",'test');//填充內容
lable:
var str = $('#lbl').text();
$('#lbl').text("Set Lbl Value");
/*獲取單選按鈕的值*/
var valradio = $("input[@type=radio]:checked").val();
/*獲取一組名爲(items)的radio被選中項的值*/
var item = $('input[@name=items]:checked').val();
/*獲取複選框的值*/
varcheckboxval = $("#checkbox_id").attr("value");
===============
/*獲取下拉列表的值*/
var selectval = $('#select_id').val();
//多選框checkbox:
$("#chk_id").attr("checked",'');
//使其未勾選
$("#chk_id").attr("checked",true);
//勾選
if($("#chk_id").attr('checked')==true)
//判斷是否已經選中
單選組radio:
$("input[@type=radio]").attr("checked",'2');
//設置value=2的項目爲當前選中項
//下拉框select:
$("#select_id").attr("value",'test');
//設置value=test的項目爲當前選中項
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")
//添加下拉框的option
$("#select_id").empty();//清空下拉框
獲取一組名爲(items)的radio被選中項的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲取select被選中項的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素爲當前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素爲當前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(
function(){ .
reset();
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
JQuery AjAx調用常用方法
$(document).ready(
function(){
$("#txtPass").bind("blur",
function(){
if($("#txtPass").val()=="")
{
alert("不能爲空!");
}
else
{
$.ajax({type:"get",
url:"ajax.aspx",data:"id="+escape($("#txtPass").val())+"", success:function(data){
if(data=="ok"){
alert("金培龍恭喜您JQuery AJAX調用成功!");
}
else{
alert("失敗!");
}
}
}
);}});});