admin管理员组文章数量:1026977
$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
Share Improve this question edited Dec 26, 2015 at 17:29 jianweichuah 1,4171 gold badge11 silver badges22 bronze badges asked Dec 26, 2015 at 8:39 aarif khanaarif khan 211 silver badge2 bronze badges 1-
You could try
document.getElementsByTagName('input')...
– Bahramdun Adil Commented Dec 26, 2015 at 8:42
1 Answer
Reset to default 3Do you have name=login
element in your HTML
page, if no then you cannot get the element and its value.
You can have something like this:
<input type="text" name="login" value="OK">
Then you can get this element by name and then get the value.
Below is what I tried:
function onLoad() {
var value= document.getElementsByName('login')[0].value;
alert("value="+value); // value=OK
}
$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
Share Improve this question edited Dec 26, 2015 at 17:29 jianweichuah 1,4171 gold badge11 silver badges22 bronze badges asked Dec 26, 2015 at 8:39 aarif khanaarif khan 211 silver badge2 bronze badges 1-
You could try
document.getElementsByTagName('input')...
– Bahramdun Adil Commented Dec 26, 2015 at 8:42
1 Answer
Reset to default 3Do you have name=login
element in your HTML
page, if no then you cannot get the element and its value.
You can have something like this:
<input type="text" name="login" value="OK">
Then you can get this element by name and then get the value.
Below is what I tried:
function onLoad() {
var value= document.getElementsByName('login')[0].value;
alert("value="+value); // value=OK
}
本文标签: javascriptError Cannot set property 39value39 of undefinedStack Overflow
版权声明:本文标题:javascript - Error Cannot set property 'value' of undefined - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745654807a2161535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论