var Price = document.getElementById("txtPrice");
        function onPriceBlur() {
            if (Price.value != "") {
                if (Price.value.substr(0, 1) != "¥") {
                    var Price = document.getElementById("txtPrice");
                    var strFuhao = "¥";
                    Price.value = strFuhao + Price.value;
                }
            }
        }上面定义的Price在函数中不能找到,希望兄弟姐妹们看看是咋回事???????

解决方案 »

  1.   

    是不是txtPrice在你的方法的下面所以根本就找不到id为txtPrice的元素啊
      

  2.   

    var Price = document.getElementById("txtPrice");
      function onPriceBlur() {
      if (Price.value != "") {
      if (Price.value.substr(0, 1) != "¥") {
      //var Price = document.getElementById("txtPrice");这句去掉
      var strFuhao = "¥";
      Price.value = strFuhao + Price.value;
      }
      }
      }
      

  3.   

    var Price = document.getElementById("txtPrice");
      function onPriceBlur() {
      if (Price.value != "") {
      if (Price.value.substr(0, 1) != "¥") {
      var strFuhao = "¥";
      Price.value = strFuhao + Price.value;
      }
      }
      }
      

  4.   

    楼主
    var Price1 = document.getElementById("txtPrice");
    var strFuhao = "¥";
    Price1.value = strFuhao + Price1.value;
    里外反冲突好像,挺奇怪
      

  5.   

    这个方法是在txtPrice控件下的onblur事件下调用的方法
      

  6.   

    var Price = document.getElementById("txtPrice");
      function onPriceBlur() {
      var Price=undefined
      if (Price.value != "") {
      if (Price.value.substr(0, 1) != "¥") {
      Price = document.getElementById("txtPrice");
      var strFuhao = "¥";
      Price.value = strFuhao + Price.value;
      }
      }
      }你那个写法其实就成了这样了
      

  7.   

    把第一行的var Price = document.getElementById("txtPrice");去掉还找不到吗?
      

  8.   

    function onPriceBlur() {
      var Price = document.getElementById("txtPrice");
      if (Price.value != "") {
      if (Price.value.substr(0, 1) != "¥") {
      var strFuhao = "¥";
      Price.value = strFuhao + Price.value;
      }
      }
    }
    你这个函数触发成功了吗?
      

  9.   

    var Price = document.getElementById("txtPrice");函数要写在windows.onload里面,因为页面没有加载你根本取不到txtPrice节点,所有你的Price一直都是空。
      

  10.   

    昨天还看到一个帖子,就是将JS的一些原理的,不过地址忘了。
    按照我昨天看的那个帖子的说法,你这个问题应该是因为:
    你在函数的内部又定义了变量Price 造成了同名。
    var Price = document.getElementById("txtPrice");
    你把方法里面的变量Price 改个名字应该就可以了
      

  11.   

    var Price = document.getElementById("txtPrice");
    你写在了函数的外面如果js代码 是写在了 head里面页面在加载的时候 先执行 var Price = document.getElementById("txtPrice");而此时 下面的代码还没有加载过来 也就是此时txtPrice 并不存在Price加载结束 没有找txtPrice 值就为undefied 建议  var Price = document.getElementById("txtPrice"); 写在函数里面的第一行代码里
      

  12.   

    页面已经出现了,此函数已经出发,var Price = document.getElementById("txtPrice");
    定义在函数里面是能用的,但是定义在外面找不到,很怪
      

  13.   

    如果 var Price = document.getElementById("txtPrice"); 比 txtPrice 先执行的话,就找不到明白????????????
      

  14.   

    你的函数功能是干嘛 有必要搞全局变量吗 
    既然是onblur事件 都定义在函数里边不就完了么 别啥事都往全局变量上去靠~~~
    最后自己把自己绕里边去了~~
      

  15.   

    当所有控件都加载完毕才可以用document.getElementById()去获得.
      

  16.   

    +++ function 外面的变量,被函数作用域里的变量覆盖掉了,但调用时还没给它赋值,因为它定义在调用的下面