$("div").scrollLeft(100); // 设置滚动条的位置

$(document).ready(function(){
$("button").click(function(){
$("div").scrollLeft(100);
});
}); <div style="border:1px solid black;width:100px;height:130px;overflow:auto">
The longest word in the english dictionary is: pneumonoultramicroscopicsilicovolcanoconiosis.
</div>
<button class="btn1">把滚动条的水平位置设置为 100px</button>

 

jQuery 参考手册 - 文档操作

   元素操作

  • 创建新html元素
var txt1="<p>Text.</p>";              // 以 HTML 创建新元素

var txt2=$("<p></p>").text("Text.");  // 以 jQuery 创建新元素

var txt3=document.createElement("p");
txt3.innerHTML="Text."; // 通过 DOM 来创建文本
  • 添加元素
$("p").append(" <b>Hello world!</b>");
$("<b>Hello World!</b>").appendTo("p");
$("<span>Hello world!</span>").insertAfter("p");
  • 替换元素
  $("p").replaceWith("<b>Hello world!</b>")
$("p").replaceAll("<b>Hello world!</b>");
  • 包裹或解开元素
  $("p").unwrap();//删除所有 <p> 元素的父元素
$("p").wrap("<div></div>")//添加父元素
$("p").wrapAll("<div></div>")//在 <div> 中包裹所有段落
$("p").wrapInner("<b></b>");//在每个 p 元素的内容上包围 b 元素:
  • 移除元素
$("p").remove();
$("p").detach();
$("p").empty();
//detach() 会保留所有绑定的事件、附加的数据,这一点与 remove() 不同,empty() 方法从被选元素移除所有内容,包括所有文本和子节点。

   Class操作

  • addClass() - 向被选元素添加一个或多个类
  • removeClass() - 从被选元素删除一个或多个类
  • toggleClass() - 对被选元素进行添加/删除类的切换操作
  • css() - 设置或返回样式属性
$("p:first").addClass("intro")
$("p:first").hasClass("intro");//是否有该class
$("p:first").removeClass("intro")//删除指定class元素
$("p").toggleClass("main");//添加类8i

//返回首个匹配元素的 background-color 值
$("p").css("background-color"); //为所有匹配元素设置 background-color 和 font-size:
$("p").css({"background-color":"yellow","font-size":"200%"});

Attr属性操作
$("#w3s").attr("href","http://www.w3school.com.cn/jquery");//设置属性

//设置多个属性
$("#w3s").attr({
"href" : "http://www.w3school.com.cn/jquery",
"title" : "W3School jQuery Tutorial"
});

//attr() 的回调函数
$("button").click(function(){
$("#w3s").attr("href", function(i,origValue){
return origValue + "/jquery";
});
});

$("p").removeAttr("id");//从任何 p 元素中移除 id 属性

最新文章

  1. Netbeans配置Xdebug
  2. c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.
  3. bzoj2243: [SDOI2011]染色--线段树+树链剖分
  4. android studio 换护眼的颜色步骤
  5. linux下如何使用sftp命令
  6. MYSQL 内存报错 Use &#39;mysqld --thread_stack=#&#39; to specify a bigger stack.
  7. SQL Server 2008 R2——VC++ ADO 操作 存储过程 向datetime类型参数传入空值
  8. java中 ==与equals 有什么区别?
  9. 代码规范[iOS]
  10. Click Models for Web Search(2) - Parameter Estimation
  11. jquery中bind事件时的命名空间用法(转)
  12. c#中文件上传(1)
  13. C#实现无物理边距真正可打印区域的绘图\打印程序开发
  14. MySQL 存储过程删除大表
  15. vsim生成VCD波形文件(verilog)
  16. 分享一个PHP调用RestFul接口的函数
  17. uva 12627
  18. postgres-xl 集体搭建
  19. springboot 入门一 hello world!
  20. leetcode — surrounded-regions

热门文章

  1. 小僧の神様・城の崎にて.PDF
  2. 由于CVE-2020-10770漏洞,k8s集群升级keycloak 8.0.0--&gt;15.0.0(由于15.0.0最近又出安全漏洞,升级为16.0.0)
  3. 高效XML绑定框架JIBX
  4. 攻防世界-file_include(绕过base64)
  5. raid 0 与raid 1的区别?
  6. 配置Centos8网络绑定
  7. 将含两列的csv文件生成二维矩阵
  8. Jmeter - Config Tips
  9. prometheus-alertmanager 告警规则
  10. 快速搭建maven私服仓库并配置