调用模式窗口,将javascript代码放在aspx页中可以正常运行,但是将代码放在js文件中时报错: 无法设置未定义或 null 引用的属性“innerText” 引用路径没有错,因为可以弹出窗口,但是获取返回值时出错,代码如下:function ChooseUser() {
var getVaule = window.showModalDialog("ChooseUserPage.aspx", "", 'dialogWidth=' + 900 + 'px;dialogHeight=' + 600 + 'px;help:no;dialogLeft=' + 150 + ';dialogTop=' + 50);
if (getVaule != null) {
var obj = getVaule;
document.getElementById("<%=txtUserName.ClientID%>").innerText = obj.name; //这里报错,无法找到innerText
document.getElementById("<%=hidUserID.ClientID%>").innerText = obj.ID;
}
}
求解啊!
var getVaule = window.showModalDialog("ChooseUserPage.aspx", "", 'dialogWidth=' + 900 + 'px;dialogHeight=' + 600 + 'px;help:no;dialogLeft=' + 150 + ';dialogTop=' + 50);
if (getVaule != null) {
var obj = getVaule;
document.getElementById("<%=txtUserName.ClientID%>").innerText = obj.name; //这里报错,无法找到innerText
document.getElementById("<%=hidUserID.ClientID%>").innerText = obj.ID;
}
}
求解啊!
解决方案 »
- 新手求助~JS中文件路径 localhost可以访问,但IP访问却报404
- 寻求JS高手可以更改kindeditor编辑
- 求助:易采网站数据采集系统中使用JAVA脚本(JavaScript)控制翻页脚本
- =======有点难度的问题=======
- 如何得知姿态栏的宽度?
- 求<body onload="fun()">的其它写法
- 刚才忘了问,母窗口可以控制新开窗口么?如何控制?
- 急,在线等!100分的标题栏按钮问题
- 在html编辑器中,如何把一段预先准备好的html代码写到ifram中?
- 如何用Java Script中的Try和catch来捕捉异常
- 求高手解答.....js疑惑
- jquery 给span赋值问题
</script><input id="txtChooseUser" type="button" onclick="ChooseUser()" value="选择员工" />
这个txtUserName是INPUT吧,它哪来的innerText属性?应该是value属性。
<%%>
<%=%>
这样的脚本代码只能在当前ASPX文件下才能解析出来,如果放在普通的HTML,JS,TXT,XML是无法解析的必须要放在ASPX文件下
2. 有母版页,不能直接写控件id
3.那你的意思是这个没有解决办法吗? 有没有其他方法能实现的? 不用每一个页面都添加代码
<script type="text/javascript">
var SeverText1 = "<%= TxtUserName.ClientID %>";
var SeverText2 = "<%= TxtUserPwd.ClientID %>";
</script>
<script src="JS/calendar.js" type="text/javascript"></script>calendar.js
function ChooseUser() {
var getVaule = window.showModalDialog("ChooseUserPage.aspx", "", 'dialogWidth=' + 900 + 'px;dialogHeight=' + 600 + 'px;help:no;dialogLeft=' + 150 + ';dialogTop=' + 50);
if (getVaule != null) {
var obj = getVaule;
document.getElementById(SeverText1).innerText = obj.name; //这里报错,无法找到innerText
document.getElementById(SeverText2).innerText = obj.ID;
}
}
一定要在定义好JS变量后在进行引用JS文件,这样JS文件可以找到你定义好的变量