ASP.NET 母版页 JavaScript 错误
将 ASP.NET Webform (v3.5) 转换为使用母版页后,我开始收到奇怪的 Javascript 错误。
内容页面有一个 javascript 块。 这里是:
<script type="text/javascript">
var attCount = 0;
function CreateAttachmentControl() {
var newAtt = document.createElement('span');
var newAttName = 'area' + attCount;
newAtt.setAttribute('id', newAttName);
newAtt.setAttribute('name', newAttName);
var newInput = document.createElement('input');
var newInputName = 'att' + attCount;
newInput.setAttribute('type', 'file');
newInput.setAttribute('id', newInputName);
newInput.setAttribute('name', newInputName);
if (newInput.addEventListener) {
newInput.addEventListener("onchange", CreateAttachmentControl, false);
} else if (newInput.attachEvent) {
newInput.attachEvent("onchange", CreateAttachmentControl);
} else {
newInput.onchange = CreateAttachmentControl;
}
var newRemove = document.createElement('a');
newRemove.setAttribute('href', 'javascript:RemoveAttachmentControl("' + attCount + '")');
newRemove.setAttribute('title', 'Remove this attachment');
newRemove.innerHTML = 'X';
newAtt.appendChild(newInput);
newAtt.appendChild(document.createTextNode(' '));
newAtt.appendChild(newRemove);
newAtt.appendChild(document.createElement('br'));
attArea.appendChild(newAtt); // error here
attCount++;
}
function RemoveAttachmentControl(n) {
// get input element
var input = document.getElementById('att' + n);
// if the input is blank dont delete
if (input.value != '' && input.value != null) {
var att = document.getElementById('area' + n);
attArea.removeChild(att);
}
}
</script>
错误是: 'attArea' 未定义
但是,我知道它不是,因为就在我的 javascript 块下面是这样的:
...<td align="left" colspan="2" style="height: 13px" id="attArea" name="attArea"></td>...
在我将 Web 表单转换为带有母版页的内容页之前,它工作得很好。 是否存在一些已知的 Javascript + 母版页问题?
谢谢
After converting an ASP.NET webform (v3.5) to use a master page, I started getting a strange Javascript error.
The content page has a block of javascript. Here it is:
<script type="text/javascript">
var attCount = 0;
function CreateAttachmentControl() {
var newAtt = document.createElement('span');
var newAttName = 'area' + attCount;
newAtt.setAttribute('id', newAttName);
newAtt.setAttribute('name', newAttName);
var newInput = document.createElement('input');
var newInputName = 'att' + attCount;
newInput.setAttribute('type', 'file');
newInput.setAttribute('id', newInputName);
newInput.setAttribute('name', newInputName);
if (newInput.addEventListener) {
newInput.addEventListener("onchange", CreateAttachmentControl, false);
} else if (newInput.attachEvent) {
newInput.attachEvent("onchange", CreateAttachmentControl);
} else {
newInput.onchange = CreateAttachmentControl;
}
var newRemove = document.createElement('a');
newRemove.setAttribute('href', 'javascript:RemoveAttachmentControl("' + attCount + '")');
newRemove.setAttribute('title', 'Remove this attachment');
newRemove.innerHTML = 'X';
newAtt.appendChild(newInput);
newAtt.appendChild(document.createTextNode(' '));
newAtt.appendChild(newRemove);
newAtt.appendChild(document.createElement('br'));
attArea.appendChild(newAtt); // error here
attCount++;
}
function RemoveAttachmentControl(n) {
// get input element
var input = document.getElementById('att' + n);
// if the input is blank dont delete
if (input.value != '' && input.value != null) {
var att = document.getElementById('area' + n);
attArea.removeChild(att);
}
}
</script>
The error is: 'attArea' is undefined
But, I know that it is not, because just below my block of javascript is this:
...<td align="left" colspan="2" style="height: 13px" id="attArea" name="attArea"></td>...
This working perfectly before I converted the webform into content page with a master page. Is there some known Javascript + Masterpage issues?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您提供的代码示例中,attArea 未定义。 对它的第一次引用是调用
attArea.appendChild()
。 它是否在您未提供的源中更高的位置声明?In the code sample you provided, attArea is undefined. The first reference to it you are calling
attArea.appendChild()
. Is it declared somewhere higher in the source that you didn't provide?我认为你缺少:
I think you are missing: