JS常用函数

获取select里的value值和option里面的值

var majorID = $("#id  option:selected").text();

两个数组组成json格式数据

var jsonArray = [];
for(var i = 0;i<userIdArray.length;i++){
	var json = {};
	for(var j=0;j<userNamesArray.length;j++){
		if(i==j){
			json.userName = userNamesArray[j];
			json.userId = userIdArray[i];
			jsonArray.push(json);
		}
	}
}
var notPerson = JSON.stringify(jsonArray);

url编码:closedLoopRule = encodeURIComponent(closedLoopRule);

单选框选择有效

if($('#checkbox_INDICATOR_REPORT_TEMPLATE').is(':checked')) {
	$("#HtmlButton_tianbao button").attr("disabled", false).removeClass("ui-button-detail-disable");
}else{
	$("#HtmlButton_tianbao button").attr("disabled", true).addClass("ui-button-detail-disable");
}

:checked
匹配所有选中的被选中元素(复选框、单选框等,select中的option),

:selected
匹配所有选中的option元素
$("select option:selected")

attr(name|pro|key,val|fn)

设置或返回被选元素的属性值。

单选框的禁用

$('input:radio:first').attr('checked', 'checked');

addClass(class|fn)

为每个匹配的元素添加指定的类名。

$("p").addClass("selected");
$("p").addClass("selected1 selected2");

each(callback)

以每一个匹配的元素作为上下文来执行一个函数。

$("img").each(function(i){
   this.src = "test" + i + ".jpg";
 });

如果你想得到 jQuery对象,可以使用 $(this) 函数。
可以使用 ‘return’ 来提前跳出 each() 循环。 return false;

Window setInterval()

可按照指定的周期(以毫秒计)来调用函数或计算表达式。

setInterval('alert("Hello");', 3000);

text([val|fn])

取得所有匹配元素的内容。
结果是由所有匹配元素包含的文本内容组合起来的文本。这个方法对HTML和XML文档都有效。

$("select").on('change',bind(this,this.changeView));

缓存到浏览器:localStorage.setItem(‘row’,JSON.stringify(row));

 跳转页面:location.href="/pages/authority/UserEditor.html"
返回页面:history.back()

在iframe脚本中获取host

window.top.location.host;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值