前端jquery一些基本文法

來源:互聯網
上載者:User

標籤:ret   地址   doc   err   修改   put   case   選取器   文法   

$("input[name=當前文字框的name]:checked").val()--擷取文字框的值
$("input[name=當前文字框的name]:input").val() --文字框取值
$("#文字框id").val() --- 擷取文字框值

JSON.stringify(obj) --將集合轉換成字元竄

var myObject=[{name: ‘dahuang‘ , id: 2 },{name:‘dahuang2‘,id:3},{name:‘dahuang3‘,id:4}] ----聲明一個 對象的集合

JSON.stringify(對象); //對象轉換字串
JSON.parse(字串); //字串轉對象

對象名["屬性名稱"] = 屬性值;// 對象中加一個屬性
$(obj).attr("屬性名稱", "屬性值");修改屬性值

----清空表單內容
($("#選取器"))[0].reset();


-----js中的replaceall------------------------------------------------------
str.replace(new RegExp(/(要轉內容)/g),‘想轉內容‘)

-----最常規的一個ajax-------------------------------------------------
$.ajax({
url: "./TestXHR.aspx", //請求地址
type: "POST", //請求方式
data: { name: "super", age: 20 }, //請求參數
dataType: "json",
success: function (response) {
// 此處放成功後執行的代碼
alert(1);
},
error: function (status) {
alert(2);
// 此處放失敗後執行的代碼
}
});

-----------------------------------------------
-------------------------------------------------
----兩個介面, 介面1擷取介面2的值 返回到ids中 (例子:CDCPro singlePage :jhbbldjglk.jsp和zzlist.jsp )

--介面1的function代碼
function myclick3()
{
var ids = window.showModalDialog(‘mytest1.jsp‘,null,‘dialogWidth=1000px;dialogHeight=1000px‘);
}
--介面2的function代碼
function test55(){
window.returnValue = "asdasda";

window.close();
}

 


----------------------------------------------------------
-----------------------------------------------------------
--- 擷取table 的第i行第j列的值

$(‘#mytable tr‘).each(function (i) {
var td[i]=$(this).children(‘td‘).eq(0).html(); //擷取table

}

});


-----------------------------頁面載入時 添加onchange事件

$(document).ready(function () {

$("#sTwo").combobox({

onChange: function (n,o) {

alert("我是老大!");

}

});

});

-----------------------
/* //遍曆td迴圈擷取報告卡編號
i=i+1;
var bgkbh="";
$(‘#mytable tr‘).each(function (t) {
if(i==t){
bgkbh=$(this).children(‘td‘).eq(0).html(); //擷取table
}
});
*/


------------------------js轉碼(中文----》亂碼)
var GB2312UnicodeConverter = {
ToUnicode: function (str) {
return escape(str).toLocaleLowerCase().replace(/%u/gi, ‘\\u‘);
}
, ToGB2312: function (str) {
return unescape(str.replace(/\\u/gi, ‘%u‘));
}
};
建立方法,直接調用 GB2312UnicodeConverter.ToUnicode(str);

 

-------亂碼轉回中文。decodeURI(str);

 

-------------遍曆test1 from中的所有input
$(‘#test1 input‘).each(function(){
alert(i);
i=i+1;
var name = this.name;
alert(name);
});

 

前端jquery一些基本文法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.