jquery的一些操作
1. 增加一个class:
$(".default").addClass("hover_s");
2. 移除一个class:
$(".default").removeClass("default ");
3、获取全部div
$('div')
4、在界面完成加载之后做些什么
$(function () {
});
$(document).ready(function () {
});
$(window).load(function () {
});
window.onload = function () {
}
5、获得元素宽度
$('#mPanelTitle').outerWidth(true);
6、获得宽度高度
1,获取屏幕的高度和宽度(屏幕分辨率): window.screen.height window.screen.width2, 获取屏幕工作区域的高度和宽度(去掉状态栏): window.screen.availHeight window.screen.availWidth 3,网页全文的高度和宽度: document.body.scrollHeight document.body.scrollWidth 4,滚动条卷上去的高度和向右卷的宽度: document.body.scrollTop document.body.scrollLeft 5,网页可见区域的高度和宽度(不加边线): document.body.clientHeight document.body.clientWidth 6,网页可见区域的高度和宽度(加边线): document.body.offsetHeight document.body.offsetWidth
7、判断是否有class
$('div').hasClass('redColor')
8、radio的一些操作
1)设置选中
$("input[name='types']:eq(0)").attr("checked",'checked');
$("#single_chose").click(); //其中一个radio
$("[name='single_answer']").prop("checked", true);
$("input[name='types']:eq(0)").prop("checked",true);
2)去除选中
$("[name='ejlx1']").removeAttr("checked");
$("[name='single_answer']").prop("checked", false);
9、动态给table增加数据
<table id="question_tbl" style="margin:10px;width:95%" border="1">
<tr style="background-color:#EDEDED">
<th style="width:70px">问题类型</th>
<th >问题内容</th>
<th style="width:180px">选项</th>
<th style="width:50px">答案</th>
<th style="width: 70px">回答人数</th>
@*<th >操作</th>*@
</tr>
</table>
function load_question_list(list) {
clear_question_list();
list.forEach(item => {
var tr1 = document.getElementById('question_tbl').insertRow();
var c0 = tr1.insertCell(0);
var c1 = tr1.insertCell(1);
var c2 = tr1.insertCell(2);
var c3 = tr1.insertCell(3);
var c4 = tr1.insertCell(4);
//var c5 = tr1.insertCell(5);
c0.innerHTML = '<span name="question_type">' + item.question_type_str + '</span>';
c1.innerHTML = item.question_content;
c2.innerHTML = item.option_html;
c3.innerHTML = item.answer;
c4.innerHTML = item.answer_count;
})
}
清空table
function clear_question_list() {
var tb = document.getElementById('question_tbl');
var ch = document.getElementsByName('question_type');
for (i = ch.length - 1; i >= 0; i--) {
var tr = ch[i].parentNode.parentNode;
var index = tr.rowIndex;
tb.deleteRow(index);
}
}

浙公网安备 33010602011771号