我有个页面,有很多textbox,有些我要拿来做判断不为空,但id都已经固定,没什么规律。有什么办法不用一个一个判断吗?
解决方案 »
- jquery 如何查找之后出现的元素
- 1 jquerey如何有智能提示 2 $(document).ready(直接跟函数叫什么 3 $("#tab tr:even") 这是什么选择符号
- JQuery的hide和show不起作用?
- 求教一个基础问题:一个变量最大能存储多少个字节??
- 低手初级问题,请大家帮忙!!在线给分!图片下边放一个超级连接,一点就直接另存上边的图片,如何实现???用JS??
- 请问如何按下一次按钮后,仅刷新一次页面??
- 如何去掉自动关闭窗口时弹出的对话框?
- 5星级DHTML程序,在线VML图像画板2003.9(原创)
- 关于window.confirm的问题,简单问题解决后既散分
- echarts做出来以后,整个图都变杂乱了是什么原因?
- 返回并刷新的代码,请大家帮忙。
- 函数语法问题
<html>
<head>
<script>
function IsNulls(){
var isnull = false;
var ipt = document.getElementsByTagName("input");
for(var i=0;i<ipt.length;i++){
//判断是是否是textbox
if(ipt[i].type=="text"&&ipt[i].value=="") {
isnull = true;
break;
}
}
if(isnull)alert("null");else alert(" not null");}
</script></head>
<body>
<input id="asd" type="text"/>
<input id="v12" type="text"/>
<input id="as3d" type="text"/>
<input id="d412" type="text"/>
<input id="s12" type="text"/>
<hr/>
这是测试用的按钮没事件触发<input type="button" value=""/>
<hr/>
<input type="button" value="check null" onclick="IsNulls();">
</body>
<html>
就是我在我想判断的textbox上加种属性,然后根据获取同种属性的控件来,就像你根据getElementsByTagName("input")类似,加种属性的话应该就不会影响原来的程序。
或者是不是还有一种方式是可以获取在某个区间内的所有同类控件,以上只是构思,希望各位不吝赐教
放在同一个div中,使用同一个id或者class试试,这个能否举个简单例子
<head>
<script>
function IsNulls(){
var isnull = false;
var ipt = document.getElementsByTagName("input");
for(var i=0;i<ipt.length;i++){
//判断是是否是textbox
if(ipt[i].type=="text"&&ipt[i].check=="true"&&ipt[i].value=="") {
isnull = true;
break;
}
}
if(isnull)alert("null");else alert(" not null");}
</script></head>
<body>
<input id="asd" type="text" check="true"/>
<input id="v12" type="text" check="true"/>
<input id="as3d" type="text" check="true"/>
<input id="d412" type="text"/>
<input id="s12" type="text"/>
</div>
<hr/>
这是测试用的按钮没事件触发<input type="button" value=""/>
<hr/>
<input type="button" value="check null" onclick="IsNulls();">
</body>
<html>
如果是c# 中的话,也可以这样
<asp:TextBox ID="TextBox1" runat="server" check="false"></asp:TextBox>
但是会有警告
<html>
<head>
<script>
function IsNulls(){
var isnull = false;
var ipt = document.getElementsByTagName("input");
for(var i=0;i<ipt.length;i++){
//判断是是否是textbox
if(ipt[i].type=="text"&&ipt[i].check=="true"&&ipt[i].value=="") {
isnull = true;
break;
}
}
if(isnull)alert("null");else alert(" not null");}
</script></head>
<body>
<input id="asd" type="text" check="true"/>
<input id="v12" type="text" check="true"/>
<input id="as3d" type="text" check="true"/>
<input id="d412" type="text"/>
<input id="s12" type="text"/>
</div>
<hr/>
这是测试用的按钮没事件触发<input type="button" value=""/>
<hr/>
<input type="button" value="check null" onclick="IsNulls();">
</body>
<html>支持这个方法
tylwzq12344321 <asp:TextBox ID="TextBox1" runat="server" check="false"></asp:TextBox>
这个好像没check这属性吧