var navRoot = document.getElementById("menu").getElementsByTagName("LI");
可以获取到所有form再根据它的属性去 区分
我是个新手,不太明白,大家能否直接帮我改以下javascript , 把它定位在某个form上呢:function foo(e) { var input_cart=document.getElementsByTagName("INPUT"); var input_all=0; for (var i=0; i<input_cart.length; i++) { if (input_cart[i].type=="text" && input_cart[i].value!="") {
input_all=input_all+1; //alert(input_all); } } if (input_all==0) { alert("Please input one of the quantity of products that you want before you submit,thanks!"); return false; } }
先确定哪个form_id,在确定form中的子结点input var navRoot = document.getElementById("form_id").getElementsByTagName("input");
我改成以下后,代码好象不起作用了: function foo(e) { var input_cart=document.getElementById("pro_search").getElementsByTagName("input"); var input_all=0; for (var i=0; i <input_cart.length; i++) { if (input_cart[i].type=="text" && input_cart[i].value!="") {
input_all=input_all+1; //alert(input_all); } } if (input_all==0) { alert("Please input one of the quantity of products that you want before you submit,thanks!"); return false; } }
var input_cart=document.getElementsByTagName("INPUT");
var input_all=0;
for (var i=0; i<input_cart.length; i++) {
if (input_cart[i].type=="text" && input_cart[i].value!="") {
input_all=input_all+1;
//alert(input_all);
}
}
if (input_all==0)
{
alert("Please input one of the quantity of products that you want before you submit,thanks!");
return false;
}
}
var navRoot = document.getElementById("form_id").getElementsByTagName("input");
function foo(e) {
var input_cart=document.getElementById("pro_search").getElementsByTagName("input");
var input_all=0;
for (var i=0; i <input_cart.length; i++) {
if (input_cart[i].type=="text" && input_cart[i].value!="") {
input_all=input_all+1;
//alert(input_all);
}
}
if (input_all==0)
{
alert("Please input one of the quantity of products that you want before you submit,thanks!");
return false;
}
}