admin管理员组文章数量:1427281
Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function
. There is hidden fields that hold all student pair that as <input type="hidden" id="_hidden_studentname_{somestudentid}" value="aStudentName">
, here {somestudentid} only indicate it as student id variable. The purpose of this is try to get a student name by student id.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).attr("value"); // line 3
dojo.byId("_student_text").attr("value", studentName);
});
So dojo doesn't allow variable put in dojo.byId()
? I am pretty sure the <input type="hidden">
with that id does exist....
Weird, line one works fine but line 3 give me TypeError: dojo.byId(...).attr is not a function
. There is hidden fields that hold all student pair that as <input type="hidden" id="_hidden_studentname_{somestudentid}" value="aStudentName">
, here {somestudentid} only indicate it as student id variable. The purpose of this is try to get a student name by student id.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).attr("value"); // line 3
dojo.byId("_student_text").attr("value", studentName);
});
So dojo doesn't allow variable put in dojo.byId()
? I am pretty sure the <input type="hidden">
with that id does exist....
1 Answer
Reset to default 6Note how you were using dijit.byId
in Line 1, but using dojo.byId
in line 3. The former returns a widget (which has an attr
function), wheras dojo.byId
returns a DOM element, which does not have an attr
method.
DOM elements can manipulate attributes directly, so you can update the code to use something.value = 'some other value';
.
dojo.connect(dijit.byId('_studentId_id'), 'onChange', function (val) {
var studentId=dijit.byId("_studentId_id").attr("value"); // line 1
var id="_hidden_studentname_"+studentId;
var studentName=dojo.byId(id).value; // line 3
dojo.byId("_student_text").value =studentName;
});
本文标签: javascriptDojo TypeError dojobyId()attr is not a functionStack Overflow
版权声明:本文标题:javascript - Dojo: TypeError: dojo.byId(...).attr is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745494922a2660765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论