$(document).ready(function () {
$('#chkAll').selectall('chk');
$('#btnDelete').checknull('chk');
})
一下代码我写在页面里就没错,但如果写在js文件里面,就会提示找不到checknull方法,请问为什么?怎么改?
$.fn.extend({
selectall: function (args) {
/// <summary>
/// 设置全选和反选
/// </summary>
/// <param name="args">子项checkbox的name值。</param>
var parent = $(this); //父项checkbox
var childName = args; //子项checkbox的name值
//全选
$(this).click(function () {
if ($(this).attr('checked')) {
$(':checkbox[name=' + childName + ']').attr('checked', true);
}
else {
$(':checkbox[name=' + childName + ']').attr('checked', false);
}
})
//子选项勾选或取消全选
var children = $(':checkbox[name=' + childName + ']');
$(children).click(function () {
if ($(':checkbox[name=' + childName + ']:checked').length == $(children).length) {
$(parent).attr('checked', true);
}
else {
$(parent).attr('checked', false);
}
})
},
checknull: function (args) {
/// <summary>
/// 检查是否未选择项
/// </summary>
/// <param name="args">子项checkbox的name值。</param>
var childName = args; //子项checkbox的name值
$(this).click(function () {
if (!confirm('是否确定删除?')) {
return false;
}
if ($(':checkbox[name=' + childName + ']:checked').length == 0) {
alert('未选择项!');
return false;
}
})
}
});
$('#chkAll').selectall('chk');
$('#btnDelete').checknull('chk');
})
一下代码我写在页面里就没错,但如果写在js文件里面,就会提示找不到checknull方法,请问为什么?怎么改?
$.fn.extend({
selectall: function (args) {
/// <summary>
/// 设置全选和反选
/// </summary>
/// <param name="args">子项checkbox的name值。</param>
var parent = $(this); //父项checkbox
var childName = args; //子项checkbox的name值
//全选
$(this).click(function () {
if ($(this).attr('checked')) {
$(':checkbox[name=' + childName + ']').attr('checked', true);
}
else {
$(':checkbox[name=' + childName + ']').attr('checked', false);
}
})
//子选项勾选或取消全选
var children = $(':checkbox[name=' + childName + ']');
$(children).click(function () {
if ($(':checkbox[name=' + childName + ']:checked').length == $(children).length) {
$(parent).attr('checked', true);
}
else {
$(parent).attr('checked', false);
}
})
},
checknull: function (args) {
/// <summary>
/// 检查是否未选择项
/// </summary>
/// <param name="args">子项checkbox的name值。</param>
var childName = args; //子项checkbox的name值
$(this).click(function () {
if (!confirm('是否确定删除?')) {
return false;
}
if ($(':checkbox[name=' + childName + ']:checked').length == 0) {
alert('未选择项!');
return false;
}
})
}
});
解决方案 »
- javascript object 一个最基础的问题,键名必须有吗?
- js混淆
- 想给连接加一个target=_blank
- 请教一个javascript 回调函数问题
- 怎么触发input file弹出对话框的事件?FF支持的
- JavaScript MVC开发,用大量的事件,性能如何?
- var a=document.getElementsByTagName("input");什么意思?
- 在页面上如何点击MSN的名字时调用msn?
- var wrd = new ActiveXObject("Word.Application");的问题
- frame的问题
- 随便写着玩的,50行JS实现的高级缩放效果,貌似别人用400行才实现。
- extjs中ext_resources\css下有多个样式文件 都是对应什么的呀?
$.fn.extend({
selectall: function (args) {
},
checknull: function (args) {
}
});
你可以去试试 实现代码不用写$.fn.extend({
selectall: function (args) {
alert(1);
},
checknull: function (args) {
alert(2);
}
});放在另外文件里引用
在调用应该是没错的
selectall 这个方法可以运行吗