gpt4 book ai didi

javascript - 使用 jQuery 更改 html 目录属性

转载 作者:行者123 更新时间:2023-11-30 13:10:29 26 4
gpt4 key购买 nike

我想在页面加载后更改 HTML dir 属性;我怎样才能做到这一点?我需要使用 .ready() 函数吗?目前它看起来像:

jQuery("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");

我怎样才能把它写在脚本中;我需要在 .ready() 函数或 .load() 中编写吗?

<div class="header">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
jQuery("html").attr("dir", "rtl")?
</script>

代码如下所示:

这是我的CSS

body.right-to-left li {
float:right;
direction: rtl;
}

最佳答案

尽可能简单...

将您的代码放入... document.ready()

<script>
$(document).ready(function(){
$("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");
});
</script>

还有一个解释ready()load() 函数的链接..

http://4loc.wordpress.com/2009/04/28/documentready-vs-windowload/

关于javascript - 使用 jQuery 更改 html 目录属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030792/

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