Lou*_*s W 1 javascript prototypejs internet-explorer-7
对于下面的代码,我在IE中遇到了一些问题.传递给函数的第二个参数应该是对单击项目的引用.这在FF和Safari中运行良好,但是当我在IE7中测试它时会出错.IE似乎得到了元素(如在控制台中看到的),但每当我尝试用它做任何事情时,我都会得到错误:
"对象不支持此属性或方法"
谢谢您的帮助.
<!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>
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
<script language="javascript" type="text/javascript">
var Test = {
doIt: function(str, btn) {
console.log(str);
console.log(btn);
if (btn.hasClassName('red')) {
console.log('has red');
} else {
console.log('doesn\'t');
}
}
};
</script>
<a href="#" onClick="Test.doIt('hello', this)" class="red">Test</a>
</body></html>
Run Code Online (Sandbox Code Playgroud)
问题是btn不会自动拥有该方法hasClassName- 这是一个Prototype扩展.
要使用原型扩展函数扩展元素,请在以下位置添加以下行 doIt():
btn = $(btn); // Extends element with Prototype functions.
Run Code Online (Sandbox Code Playgroud)
你的代码应该在那里工作.
| 归档时间: |
|
| 查看次数: |
433 次 |
| 最近记录: |