在IE7中添加onclick属性

时间:2013-06-22 11:17:56

标签: jquery onclick internet-explorer-7

$(".awp_class_horizantal").attr('onclick', 'changeTextAdd(this.id)');

以上代码在IE7中不起作用,但在其余浏览器中工作。

任何人都可以建议我如何添加在IE7中工作的onclick属性

$(".awp_class_horizantal").click(function() {
            changeTextAdd(this.id);
            });

上面的代码正在运行,但是它为我提供了无响应的脚本错误。

我必须在该函数本身中调用changeTextAdd函数。

由于

2 个答案:

答案 0 :(得分:1)

试试这个$(".awp_class_horizantal").prop('onclick', 'changeTextAdd(this.id)');

for more info

答案 1 :(得分:0)

确保您使用的是支持Internet Explorer 7的jQuery版本。我建议您尝试加载jQuery 1.8.3以确保。其次,请确保仅在加载DOM后运行代码。

$(document).ready(function () {
    $(".aw_class_horizontal").on("click", function () {
        changeTextAdd( this.id );
    });
});

请注意更新的“水平”拼写。根据你的课程,你可能会或可能不会成为一个问题。如果您遇到任何问题,您应该检查changeTextAdd正在做什么,看看它是否可以简化。

相关问题