您好我从url获取数据,然后将其存储到变量中,然后使用document.getElementById()。innerHTML在html中显示数据但是我不断收到此错误的原因
“[错误] TypeError:null不是对象(评估'document.getElementById(”firstname“)。innerHTML = fname') 全球代码“
由于
<script type="text/javascript">
var fname = ""
var lname = ""
var user = ""
var pass = ""
var email = ""
var con = ""
var group = ""
var uri_dec = ""
var uri_dec1 = ""
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
fname = $.urlParam('fname');
lname = $.urlParam('lname');
user = $.urlParam('user');
email = $.urlParam('email');
con = $.urlParam('con');
group = $.urlParam('group');
uri_dec = decodeURIComponent(con);
uri_dec1 = decodeURIComponent(group);
console.log($.urlParam('fname'));
console.log($.urlParam('lname'));
console.log($.urlParam('user'));
console.log($.urlParam('email'));
console.log($.urlParam('con'));
console.log($.urlParam('group'));
document.getElementById("firstname").innerHTML = fname
document.getElementById("lastname").innerHTML = lname;
document.getElementById("username").innerHTML = user
document.getElementById("email").innerHTML = email
document.getElementById("country").innerHTML = uri_dec
document.getElementById("group").innerHTML = uri_dec1
</script>
<p align="center" id="firstname"></p>
<p align="center" id="lastname" class="lastname"></p>
<p align="center" id="username" class="username"></p>
<p align="center" id="email" class="email"></p>
<p align="center" id="country" class="contry"></p>
<p align="center" id="group" class="group"></p>
答案 0 :(得分:1)
尝试按anim1.EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut };
更改innerHTML
。
答案 1 :(得分:0)
正如@SciFiThief所提到的,你的脚本在加载html之前正在执行。您需要在html标记之前包含脚本或使用准备好的文档&#39;加载html后执行脚本的功能。
//Using Jquery
$(document).ready(function(){
//your script here
});
//Using vanilla Javascript
document.addEventListener("DOMContentLoaded", function(event) {
//your script here
});