jq--动态添加 HTML 和 添加/移除指定的css
1、在指定元素下,添加 HTML
这里有两种方法,一种是使用“$("#元素").html()”;另一种是使用:“$("#元素").append”;
“$("#元素").html()”
htmlText1 += '<option value="' + thisData[i].id + '">' + thisData[i].name + '</option>'; $("#newSelect1").html(htmlText1); //.html会覆盖指定元素下的内容,所以需要有变量进行接收
“$("#元素").append”:
$("#newSelect2").append('<option value="' + thisData[i].id + '">' + thisData[i].name + '</option>') //.append会在指定元素下的内容的结尾处添加新的,不会修改原内容
2、指定位置添加/移除 指定的css
通过button的点击事件,添加指定的css
$("button").click(function(){ $("p").addClass("cssName"); });
通过button的点击事件,移除指定的css
$("button").click(function(){ $("p").removeClass("cssName"); });