前端知识小技巧
1、保留表格首行(标题),清空列表
$("#table tr:not(:first)").html("");
$("#table tr:not(:first)").empty("");
2、通过属性隐藏input标签类型
<input type=“text” style="visibility:hidden">//隐藏,但会占位置
<input type=“text” style="display:none">//隐藏,但不会占位置
通过jquery隐藏与显示
$("p").hide();
$("p").show();
3、前台动态添加option
js动态添加optionvar sel= document.getElementById("Selected1");sel.options.add(new Option("name","id"));
jquery动态添加option$("#selectId").append("<option value='"+value+"'>"+text+"</option>");
jquery移除所有option$("#selectId option").remove();
4、jquery获得选中select值
第一种方式 | 第二种方式 |
$('#selectId option:selected').text();//选中的文本
$('#selectId option:selected') .val();//选中的值
|
$("#selectId").find("option:selected").text();
$("#selectId").find("option:selected").val();
|
$("#selectId").get(0).selectedIndex;//获得索引
5、jquery遍历
var arr = [{ id: "1",name: "张三" },{id: "2", name: "李四" },{id: "3", name: "王五" }];
$.each( arr, function(index, content){
alert( "index= " + index + ",id= " + content.id+",name="+content.name);
});
6、jsp引入外部页面的方法
|
|
|
|
|
|
(持续更新中~)