日期:2014-05-16 浏览次数:20419 次
<script type="text/javascript"> function CheckInput(obj,type){ var content = type+'content'; //alert(content); alert(obj.content.value); //问题出在这里,怎么获取不到当前表单项的值呢? return false; } </script> <form action="save.php" method="post" name="aform" onsubmit="return CheckInput(this,'a')"> <input type="text" name="acontent" /> <input type="submit" name="submit" value="发布" /> </form> <form action="save.php" method="post" name="bform_1" onsubmit="return CheckInput(this,'b')"> <input type="text" name="bcontent" /> <input type="submit" name="submit" value="发布" /> </form> <form action="save.php" method="post" name="bform_2" onsubmit="return CheckInput(this,'b')"> <input type="text" name="bcontent" /> <input type="submit" name="submit" value="发布" /> </form>
<script type="text/javascript"> function CheckInput(obj,type){ var content = type+'content'; alert(obj.content.value); //对象没有这么组合的。应该改为:obj.elements[content].value; return false; } </script>
------解决方案--------------------
<script type="text/javascript">
function CheckInput(obj,type){
var content = type+'content';
//alert(content);
alert(obj.content.value); //alert(obj.firstChild.value);这样写可以
//问题出在这里,怎么获取不到当前表单项的值呢?
return false;
}
</script>