当前位置:编程学习 > JAVA >>

jsp页面javascript中用document.getElementById(" ").value无法获取相应text的值

<!--                       Javascripts                       -->
  
<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.3.2.min.js"></script>

<!-- jQuery Configuration -->
<script type="text/javascript" src="resources/scripts/simpla.jquery.configuration.js"></script>

<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>

<script type="text/javascript">
function yanzheng(){
var name=document.getElementById('depName').value;
alert(name);
if(name==""){
alert("部门名不能为空!!!");
return false;
}
}

</script>


<div id="adddepart" style="display: none"> <!--新增部门-->

<h3 align="center">新增部门</h3>

<form name="addpart" action="#" method="post" onsubmit="return yanzheng()">
<p align="center">
<strong>部门名称:</strong>
<input id="depName" type="text" name="dep.departName" placeholder="请输入部门名称" />
</p>

<p align="center">
<strong>部门描述:</strong>
<input type="text" name="dep.departDesc" />
</p>
<p align="right">
<input class="button" type="submit" value="提交"/>
</p>
</form>

</div> <!-- End #adddepart -->


//是不是导入的JS文件的原因,将这个document.getElementById(" ").value给屏蔽掉了? javascript jsp jquery function --------------------编程问答-------------------- 这个方法怎么用?这样写报错。document.getElementById( ' <%= depName.ClientID %> ').value;
<script type="text/javascript">
function yanzheng(){
//var name=document.getElementById('depName').value;
var name=document.getElementById( ' <%= depName.ClientID %> ').value; 
alert(name);
if(name==""){
alert("部门名不能为空!!!");
return false;
}
}

</script> --------------------编程问答-------------------- 你有 jQuery 了,怎么还这样费劲写,一夜回到解放前? --------------------编程问答-------------------- 大侠求指教,应该怎么做? --------------------编程问答--------------------
function yanzheng(){
$(document).ready(function() {
var name = document.getElementById("depName").value;
alert(name);
});
}
--------------------编程问答-------------------- onsubmit="yanzheng()" --------------------编程问答-------------------- <input id="depName" type="text" name="dep.departName" placeholder="请输入部门名称" value="111111" /> --------------------编程问答-------------------- var name=document.getElementById( ' <%= depName.ClientID %> ').value; 
改写为 var name = jQuery("#depName").val(); 试一下这个,看能取到不  --------------------编程问答-------------------- 不太可能哦,这种原生态的js肯定是没有问题的 --------------------编程问答-------------------- 给 INPUT ELEMENT 添加 VALUE 属性 --------------------编程问答-------------------- 是不是导入的JS文件的原因,将这个document.getElementById(" ").value给屏蔽掉了?
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,