1.导入jquery cdn
<head>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
</head>
2.选择器操作
<body>
<p>If you click on me, I will disappear.</p>
<button id="test1">消失id </button>
<button class="test2">消失class</button>
<script type="text/javascript">
$(document).ready(function(){
$("#test1").hide()
$(".test2").hide()
$('p').hide()
})
</script>
</body>
3.显示隐藏 事件操作
$("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); });
change事件
<select> <option>js</option> <option>python</option> <option>css</option> <option>html</option> </select>
$("select").change(function(){ a = $("select").val() alert(a) })
获取input的值!
<input></input> <button id="sub">SUBMIT</button> <div id="ttt" uid=""></div> $("#sub").click(function(){ a = $("input").val() $("#ttt").html(a) })
赋值属性
<div id="ttt" uid=""></div>
<script type="text/javascript">
$("#ttt").attr("uid",'hehe')