请问怎么在JavaScript中访问HTML标签中的对象,比如:
<html>
<head>
<script>
function check(){
}
</script>
</head>
<body>
<html:form action="form.do" name="mf" id="mf">
<html:text property="name"></html:text>
</html:form>
</body>
</html>
请问怎么在JavaScript中验证<html:text property="name"></html:text>是否为空,好像用id,和name都不可以表示这个对象,应该怎样呢?
<html>
<head>
<script>
function check(){
}
</script>
</head>
<body>
<html:form action="form.do" name="mf" id="mf">
<html:text property="name"></html:text>
</html:form>
</body>
</html>
请问怎么在JavaScript中验证<html:text property="name"></html:text>是否为空,好像用id,和name都不可以表示这个对象,应该怎样呢?
具体的例子我引用你给的给你说一下吧: <html:form action="form.do" name="mf" id="mf">
<html:text property="name"> </html:text>
</html:form>
在JavaScript中写
function check(){
var name = document.mf.name.value();
if(name==null){
写你想处理的代码就可以了
}
}
if(document.getElementById("text").value==""){
处理代码
}else{
return true;
}
}
<body>
<html:form action="form.do" name="mf" id="mf">
<html:text property="name" id="text"> </html:text>
</html:form>
</body>
<html>
<head>
<script>
function check(){
var value =document.getElementById("name").value;
if(value == "")
alert("name的值为空");
else
alert("name的值为 "+ value)
}
</script>
</head>
<body>
<form action="form.do" name="mf" id="mf">
name :<input type="text" property="name" id ="name"><br>
<input type="button" value="测试是不是为空" onclick="check()">
</form>
</body>
</html> 我给你实现了下,你看看吧。
document.getElementsByName(name)
document.getElementsByName(name)
document.getElementsByTagName(name)