您的位置:首页 > Web前端 > JQuery

Jquery小知识

2015-07-15 23:16 567 查看
1.

$(document).ready(function(){
$('form').find("input[type=textarea],input[type=password],textarea").each(function(ev)
{
if(!$(this).val()){
$(this).attr("placeholder","Typeyouranswerhere");
}
});
});
//获取属性
HowcanIselectanelementbynamewithjQuery?

youcanusetheattributeselector

$('td[name=tcol1]')//matchesexactly'tcol1'

$('td[name^=tcol]')//matchesthosethatbeginwith'tcol'
//通过name选择[/code]
HowcanIknowwhichradiobuttonisselectedviajQuery?

TogetthevalueoftheselectedradioNameitemofaformcalled'myForm':

[code]$('input[name=radioName]:checked','#myForm').val()//注意这条棒哒哒的选择

//判断哪个radio被选中[/code]

使用trigger()方法模拟事件

$("#btn").trigger("click");
//模拟点击http://blog.csdn.net/lijunling2008live/article/details/7457396

使用标准效果列队,举个例子,我们可以在
<divid="foo">
.slideUp()
.fadeIn()
动画之间设置800毫秒的延时:



1
$('#foo').slideUp(300).delay(800).fadeIn(400);


//设置动画延迟

info+id是一个select的id

val=$('#info'+id).val();
varselect='#info'+id+'option:selected';
varnewcontent=$(select).text();

//取得select选中的optionvalue和text

setTimeout(
function()
{
//dosomethingspecial
},5000);


//实打实的延迟5秒

绑定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: