开始觉得没办法下手去做。经过头的指点,感觉有点头绪。
<script type="text/javascript">
function CheckValue()
{
var attributeName = document.getElementById("<%=this.attrATTRIBUTE_NAME.ClientID %>");
if (attributeName.value.trim() == "")
{
alert("Attribute name is not null");
attributeName.focus();
return false;
}
if (dlAttributes != null)
{
var tbAttributes = dlAttributes.getElementsByTagName("input");
for (var i = 0; i < tbAttributes.length; i++)
{
if (tbAttributes[i].id.indexOf("txtAttributeValue") > 0)
{
if (tbAttributes[i].value.trim().length == 0)
{
alert("Attribute value is not null");
tbAttributes[i].focus();
return false;
}
}
}
}
}
</script>
js代码如上:原来以为只有intput控件才可以使用getElementsByTagName方法。现在知道服务器端控件在解析时也解析成个intput控件,它当然也是可以使用的。
刚开始没有加if (dlAttributes != null)这个条件,结果在运行时报错“ error: object is not null”.费了好大力气才知道是这个地方出错了。
自己得从头开始学起啊,会的东西太少了。