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在函数中不能找到,希望兄弟姐妹们看看是咋回事???????
function onPriceBlur() {
if (Price.value != "") {
if (Price.value.substr(0, 1) != "¥") {
var Price = document.getElementById("txtPrice");
var strFuhao = "¥";
Price.value = strFuhao + Price.value;
}
}
}上面定义的Price在函数中不能找到,希望兄弟姐妹们看看是咋回事???????
function onPriceBlur() {
if (Price.value != "") {
if (Price.value.substr(0, 1) != "¥") {
//var Price = document.getElementById("txtPrice");这句去掉
var strFuhao = "¥";
Price.value = strFuhao + Price.value;
}
}
}
function onPriceBlur() {
if (Price.value != "") {
if (Price.value.substr(0, 1) != "¥") {
var strFuhao = "¥";
Price.value = strFuhao + Price.value;
}
}
}
var Price1 = document.getElementById("txtPrice");
var strFuhao = "¥";
Price1.value = strFuhao + Price1.value;
里外反冲突好像,挺奇怪
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;
}
}
}你那个写法其实就成了这样了
var Price = document.getElementById("txtPrice");
if (Price.value != "") {
if (Price.value.substr(0, 1) != "¥") {
var strFuhao = "¥";
Price.value = strFuhao + Price.value;
}
}
}
你这个函数触发成功了吗?
按照我昨天看的那个帖子的说法,你这个问题应该是因为:
你在函数的内部又定义了变量Price 造成了同名。
var Price = document.getElementById("txtPrice");
你把方法里面的变量Price 改个名字应该就可以了
你写在了函数的外面如果js代码 是写在了 head里面页面在加载的时候 先执行 var Price = document.getElementById("txtPrice");而此时 下面的代码还没有加载过来 也就是此时txtPrice 并不存在Price加载结束 没有找txtPrice 值就为undefied 建议 var Price = document.getElementById("txtPrice"); 写在函数里面的第一行代码里
定义在函数里面是能用的,但是定义在外面找不到,很怪
既然是onblur事件 都定义在函数里边不就完了么 别啥事都往全局变量上去靠~~~
最后自己把自己绕里边去了~~