未捕获的类型错误:不能设置属性'src'当想要切换图像时为null
Uncaught TypeError: Cannot set property 'src' of null when want to switch the image
我一直得到未捕获的TypeError:当我想切换图像时,不能设置null错误的属性'src'。
我使用这两个文件的jquery
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.2/jquery-ui.min.js"></script>
javascript代码
function correctcheck() {
var value = document.getElementById("codes").value;
var img = document.getElementById("gameplay");
if (value == "$player //Declare player as an object'n'n$player = 'Artix' //Set player to Artix'n'necho = 'I am'.$player.'I got the key' // Echo the message'n'n") {
img.src="correct.gif"; //error is here
window.alert("Congratulation. You passed forest level.");
return false;
} else {
window.alert("Your Drag and drop code is incorrect..View tips to get correct answer.");
}
}
这是我的img src的html代码
<div class="featured">
<div class="wrap-featured grid">
<div class="slider">
<img src="Artix.png" alt = "GameBanner" name="gameplay" id "gameplay"/>
<textarea name="codes" id="codes" class="txtDropTarget" cols="80" rows="10"></textarea>
<a class="button" onClick="correctcheck()" >Run</a>
</div>
</div>
</div>
你必须在你的img标签中插入"="元素,像这样:
<img src="Artix.png" alt = "GameBanner" name="gameplay" id="gameplay"/>
必须插入$(document)。在你的代码中准备好和在你的img标签中的"="元素,像这样:
<img src="Artix.png" alt = "GameBanner" name="gameplay" id="gameplay"/>
function correctcheck() {
$(document).ready(function(){
var value = document.getElementById("codes").value;
var img = document.getElementById("gameplay");
if (value == "$player //Declare player as an object'n'n$player = 'Artix' //Set player to Artix'n'necho = 'I am'.$player.'I got the key' // Echo the message'n'n") {
img.src="correct.gif"; //error is here
window.alert("Congratulation. You passed forest level.");
return false;
} else
{
window.alert("Your Drag and drop code is incorrect..View tips to get correct answer.");
}}
)};
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 数组在递归方法中设置为null
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- Javascript排序的图像弹出窗口..可以't单独弹出
- 画布数据到图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使图像在单击时展开到不大于浏览器
- Html页面上的多个Base64图像和平滑加载
- UIAutomation放大图像
- 使用javascript在Flash中加载外部图像
- 有没有一种方法可以判断图像src是否在javascript内部返回null
- 相对图像源路径使用 jQuery 返回 null
- Jquery在ajax上设置onclick null并更改按钮图像成功
- 未捕获的类型错误:不能设置属性'src'当想要切换图像时为null
- 为什么保存值要“null”;(试图将图像保存为encode64)
- 未捕获的类型错误:不能设置属性'src'null图像库