首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

SCRIPT5007: 没法设置属性“value”的值: 对象为 null 或未定义

2012-07-29 
SCRIPT5007: 无法设置属性“value”的值: 对象为 null 或未定义function check(){var aconfirm(确定吗)i

SCRIPT5007: 无法设置属性“value”的值: 对象为 null 或未定义
function check()
  {
  var a=confirm("确定吗");
  if (a==true)
  {
  document.getElementById("lblsur").value="1";
   
  }
  else(a==false)
  {
  document.getElementById("lblsur").value="2";
  }
  }

代码执行时就报那个错了。请问改如何解决

[解决办法]
首先你的判断错了, 其次label用javascript获取的话请使用document.getElementById("lblsur").innerHTML
[解决办法]
我试了一下,这样是可以的。

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication1.WebForm4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>无标题页</title>    <script type="text/javascript">    function check()    {      var a=confirm("确定吗");      if (a)      {        document.getElementById("Label1").innerText="1";      }      else      {        document.getElementById("Label1").innerText="2";      }    }     window.onload=check;    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:Label ID="Label1" runat="server"></asp:Label>    </div>    </form></body></html> 

热点排行
Bad Request.