HTML总结笔记

1.select标签取值问题:

<select id="selector">

<option value="A" selected >a</option>

<option value="B">b</option>

<option value="C">c</option>

</select>

取A的值: $("#selector option:selected").val() 

取a的值: $("#selector option:selected").text()

2.RadioButton标签取值问题:

<input id="radioExample" name="radioExample" value="合格" checked="checked" /> 合格

<input id="radioExample" name="radioExample" value="不合格" />不合格

如果整个页面只有这一组 RadioButton,那么可以这样取值:

$("input:radio:checked").val()="合格"

如果页面有多个,需要确定取哪组的RadioButton,那么这样取值:

$("#radioExample input[name="radioExample"]:checked").val()="合格"

3.某元素滚置顶

将页面的id为linkExample的,滚至页面的顶部;

$('body,html').scrollTop($('#linkExample').offset().top);

4.给元素加鼠标浮动变小手:

#id {  cursor: pointer; }

5.给框架中的某个元素赋值;

var exampleFor="abc";

var example= $(window.parent.frames["Dialogs"].document).find("#schoolName");//Jquery获得frame中的元素
example.val(exampleFor);

赋值结束,这个元素的值就为:

$("schoolName").val="abc"

方法: 在浏览器的Console 中用这个找:window.parent.document

 6.批量获取一个div里面的一类标签;

<div id="Div">

<input type="text" value="1"/>

<input type="text" value="2"/>

<input type="text" value="3"/>

<span class="a c" id="a"/>

<span class="a b" id="b"/>

</div>

$("#Div input[type="text"]").each(function(index,obj){

//index 指第几个元素,从0 开始;

//obj.指循环到的当前标签,index=0,obj="<input type="text" value="1"/>";

obj.value;//取当前标签的value值,相当于 $("#id").val() 这个标签的值

obj.id;//取当前标签的id值;

 obj.disabled = true;//把当前标签禁用

 obj.className = 'fl icon check_dis';//取当前标签的class样式

});

$("#Div span[class="a b"]").length 返回个数:在id为Div的这个标签里的所有的span标签class ="a b"的个数;

同理:可以根据标签一致的属性 来批量获取标签来判断;

 

7.给input 标签添加placeholder

<input type="text" placeholder="yyyy-mm-dd" />

显示结果:

 

posted @ 2016-12-14 16:55  酸菜sauerkraut  阅读(118)  评论(0编辑  收藏  举报