gpt4 book ai didi

jquery - .removeAttr jQuery

转载 作者:行者123 更新时间:2023-12-01 03:47:13 26 4
gpt4 key购买 nike

我有下面这段代码:

<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script src="http://ui.jquery.com/latest/ui/effects.core.js"></script>
<style type="text/css">
p { cursor: pointer; font-size: 1.2em; }
.selected { color:red; }
</style>
<script>
$(document).ready(function() {
$('p').click(function () {
$(this).removeClass('selected', 1000);
$(this).removeAttr('class');
//$(this).removeAttr('style');
});
});
</script>
</head>
<body style="font-size:62.5%;">

<p class="selected">Click me to remove 'selected' class.</p>
<p class="selected">Click me to remove 'selected' class.</p>
<p class="selected">Click me to remove 'selected' class.</p>

</body>
</html>

所以当我点击任何 <p>该类确实被删除,属性类也被删除。然而,发生的情况是代码 style=""被注入(inject)到 <p> 的内联中.

为什么会发生这种情况以及如何消除它?点击 <p> 后给我元素 <p> 的新定义应该只是<p>some text goes here</p>

最佳答案

为什么有这种样式是因为 jquery-ui removeclass()尽管它不在文档中,但它似乎有更多参数(请参阅 soruce ),您可以使用这些参数来使用动画完成后将运行的回调:

$(document).ready(function() {
$('p').click(function () {
$(this).removeClass('selected', 1000, function() {
$(this).removeAttr('style').removeAttr("class");
});
});
});

(我不确定你为什么要这样做)。

演示:http://jsbin.com/opucon/2/ (结果演示)

关于jquery - .removeAttr jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12388725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com