============================================
- /**
- * 全选的所有指定名称的checkbox
- *@state 全选的checkbox的状态
- *@name 表格中的所有checkbox的名称
- *@author fangtf
- *@type void
- */
- function selectAll(state,name) {
- var ids = document.getElementsByName(name);
- for (var i = 0; i < ids.length; i++)
- {
- ids[i].checked = state;
- }
- }
- /**
- * 全选的所有指定id名称的同名checkbox
- *@state 全选的checkbox的状态
- *@name 表格中的所有checkbox的名称
- *@name 表格中的所有checkbox的id
- *@author fangtf
- *@type void
- */
- function selectAllCheckboxByID(state,name,id) {
- var ids = document.getElementsByName(name);
- for (var i = 0; i < ids.length; i++)
- {
- if(ids[i].id == id)
- {
- ids[i].checked = state;
- }
- }
- }
- /**
- * 全选页面上所有的checkbox
- *@state 全选的checkbox的状态
- *@author fangtf
- *@type void
- */
- function selectAlls(state)
- {
- var inputs = document.getElementsByTagName("input");
- for(var i =0;i
- {
- if(inputs[i].type == "checkbox")
- {
- inputs[i].checked =state;
- }
- }
- }
- /**
- *得到鼠标所单击的行
- *@type Object
- */
- function GetRow(oElem) {
- while (oElem) {
- if (oElem.tagName.toLowerCase() == "tr" && oElem.parentElement.tagName.toLowerCase() == "tbody") {
- return oElem;
- }
- if (oElem.tagName.toLowerCase() == "table" || oElem.tagName.toLowerCase() == "th") {
- return false;
- }
- oElemoElem = oElem.parentElement;
- }
- }
- /**
- * 全选当前行的checkbox
- *@state 全选的checkbox的状态
- *@author fangtf
- *@type void
- */
- function selectRowCheckbox(state)
- {
- var row = GetRow(window.event.srcElement);
- var cells = row.childNodes;
- for(var i=0;i<> 用js实现了点击按扭或点击Checkbox完成多个Checkbox的选择js 代码
- function clickButtonForSelectAllCheckBox(allCheckBox)
- {
- var boxs = document.getElementsByName(allCheckBox);
- var isAllSelected = true;
- for (i = 0; i < boxs.length; i++) {
- if (boxs[i].checked == false) {
- isAllSelected = false;
- }
- }
- for (i = 0; i < boxs.length; i++) {
- boxs[i].checked = !isAllSelected;
- }
- }
- function clickCheckBoxForSelectAllCheckBox(clickCheckBox, allCheckBox)
- {
- var box = document.getElementsByName(clickCheckBox)[0];
- var boxs = document.getElementsByName(allCheckBox);
- for (i = 0; i < boxs.length; i++) {
- boxs[i].checked = box.checked;
- }
- }
jsp页面的js
js 代码- "javascript">
- function checkAllCheckBox()
- {
- var flag = false;
- var projects = document.getElementsByName("typeIds");
- for (i = 0; i < projects.length; i++) {
- if (projects[i].checked == true) {
- flag = true;
- }
- }
- if (flag == false) {
- alert("请选择要删除的项");
- }
- else {
- if (!confirm("确定要删除吗")) {
- flag = false;
- }
- }
- return flag;
- }
- <td class="td1">
- <input type="checkbox" name="selectAllCheckBox"
- onclick="return clickCheckBoxForSelectAllCheckBox('selectAllCheckBox', 'typeIds')"/>
- td>
- <logic:iterate id="contenttype" name="contentTypeBean"
- property="contentTypeList">
- <tr class="contenttr">
- <td class="td1">
- <html:checkbox property="typeIds" value="${contenttype.id}"/>
- td>
- tr>
- logic:iterate>
beanAction中的代码java 代码- public class ContentTypeBean
- extends AbstractBeanAction
- {
- private Long[] typeIds;
- .....
- public String deleteContentType() throws ContentTypeException, AttributeException
- {
- ActionMessages errors = new ActionMessages();
- for (int i = 0; i < typeIds.length; i++) {
- long typeId = typeIds[i];
- getContentTypeManager().removeContentType(typeId);
- }
- return SUCCESS;
- }
- }
- {
- var cell = cells[i].childNodes[0];
- if(cell.tagName == "INPUT")
- {
- cell.checked = state;
- }
- }
- }
- /**
- *选中指定值的Radio
- *如:有两个radio,
- *第一个的name="ids",value="1"
- *第二个的name="ids",value="2"
- *调用方法selectRadio("ids","1");
- *那么数值为1的Radio将被选中
- *@name radio的名称
- *@value radio的值
- *@author fangtf
- *@type void
- */
- function selectRadio(name,value) {
- var radioObject = document.getElementsByName(name);
- if(value === "")
- {
- radioObject[0].checked = true;
- return;
- }
- for (var i = 0; i < radioObject.length; i++)
- {
- if(radioObject[i].value == value)
- {
- radioObject[i].checked = true;
- break;
- }
- }
- }
- /**
- *选中指定值的checkbox
- *如:有两个checkbox,
- *第一个的name="ids",value="1"
- *第二个的name="ids",value="2"
- *第三个的name="ids",value="3"
- *调用这个方法selectCheckbox("ids","1,2")那么数值为1,2的checkbox将被选中
- *
- *@name 要选中的checkbox数组的名称
- *@value 判断时候选中的值
- *@author fangtf
- *@type void
- */
- function selectCheckbox(name,value) {
- var checkObject = document.getElementsByName(name);
- var valuevalues = value.split(",");
- for(var j = 0; j < values.length; j++)
- {
- for (var i = 0; i < checkObject.length; i++)
- {
- if(checkObject[i].value == values[j])
- {
- checkObject[i].checked = true;
- break;
- }
- }
- }
- }
- /**
- *选中指定值的select
- *如:有一个名称为user的select
- *
- *
- *调用这个方法selectOption("user","0")那么选项为0的选项就被选中
- *
- *@name String select的名称
- *@value String 判断时候选中的值
- *@author fangtf
- *@type void
- */
- function selectOption(name,value)
- {
- var options = document.getElementsByName(name)[0].options;
- for (var i = 0; i < options.length; i++)
- {
- if(options[i].value === value)
- {
- options[i].selected = true;
- break;
- }
- }
- }
- /**
- * 全选的所有指定名称的checkbox,并改变相应改变按钮
- *@selectName checkbox的名称
- *@buttonName 按钮的名称
- *@author seagar
- *@type void
- */
- function selectAll(selectName,buttonName) {
- var ids = document.getElementsByName(selectName);
- var buttons=document.getElementsByName(buttonName);
- for (var i = 0; i < ids.length; i++){
- if(ids[i].checked==true){
- ids[i].checked=false;
- buttons[0].value="全部选择";
- }else{
- ids[i].checked=true;
- buttons[0].value="全部取消";
- }
- }
- }
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。