JavaScript、C#基础知识

来源:互联网 发布:import org.apache包 编辑:程序博客网 时间:2024/06/06 15:40

1.jquery如何使文本框获得焦点:$(”#nameInput”)[0].focus(); 


2.在 jQuery 中如何判断对象是否存在:

正确使用判断对象是否存在应该用:

if($("#id").length>0){}else{}
使用 jQuery 对象的属性 length 来判断,如果 > 0 就存在。

或者
if($("#id")[0]){} else {}


或者直接使用原生的 Javascript 代码来判断:
if(document.getElementById("id")){} else {}


3.数组声明、初始化

int[] arr; 
arr = new int[5]; // create a 5 element integer array


int[] arr2Lines; 
arr2Lines = new int[5] {1, 2, 3, 4, 5};


int[] arr1Line = {1, 2, 3, 4, 5};


初始化 
可以使用以下一种方法,在同一个语句中创建、设置并初始化多维数组: 

int[,] arr4 = new int [2,3] { {1,2,3}, {4,5,6} }; 
int[,] arr5 = new int [,] { {1,2,3}, {4,5,6} }; 
int[,] arr6 = { {1,2,3}, {4,5,6} };

4. js判断带中文的字符串的长度

var str = '哈fd我as';
//方法一
alert(str.replace(/([\u4E00-\u9FA5\uf900-\ufa2d])/g,'aa').length);
//方法二
alert(str.replace(/([^\x00-\xff])/g,'**').length);
摘自:
http://www.dewen.org/question/1189/JS验证中文字符长度


5.JQUERY 清空Select:$("#charCity").empty();

6. Select

$("#select_id").append("<option value='Value'>Text</option>");  //添加一项option
$("#select_id option[value='3']").remove(); //删除值为3的Option
$("#select_id option[text='4']").remove(); //删除TEXT值为4的Option
0 0
原创粉丝点击