使用jQuery的replaceWith()方法要注意的地方
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
div{
width:100px;
height:100px;
background-color:#CCFFFF;
border:#FF0000 solid 2px;
}
</style>
<script language="javascript" src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script language="javascript">
// 用text()或html()实现
// $(function(){
// $('div').eq(0).click(function(){
// $('div').eq(0).text("11");
// $('div').eq(1).text("");
// });
// $('div').eq(1).click(function(){
// $('div').eq(0).text("");
// $('div').eq(1).text("22");
// });
// }); //用replaceWith()实现
function initClick(){
$('div').eq(0).click(function(){
$('div').eq(0).replaceWith('<div>11</div>');
$('div').eq(1).replaceWith('<div></div>');
initClick();
});
$('div').eq(1).click(function(){
$('div').eq(0).replaceWith('<div></div>');
$('div').eq(1).replaceWith('<div>22</div>');
initClick();
});
}
$(function(){
$('div').eq(0).click(function(){
$('div').eq(0).replaceWith('<div>11</div>');
$('div').eq(1).replaceWith('<div></div>');
initClick();
});
$('div').eq(1).click(function(){
$('div').eq(0).replaceWith('<div></div>');
$('div').eq(1).replaceWith('<div>22</div>');
initClick();
});
});
</script>
</head> <body>
<div></div>
<div></div>
</body>
</html>
使用jQuery的replaceWith()方法要注意的地方的更多相关文章
- 避免使用jQuery的html方法来替换标签,而是使用replaceWith方法
tblCostSplit.html内容: <nobr title="">只想显示里面内容,去掉nobr标签</nobr> <nobr title=&q ...
- 关于Jquery中ajax方法data参数用法的总结
data 发送到服务器的数据.将自动转换为请求字符串格式.GET 请求中将附加在 URL 后.查看 processData 选项说明以禁止此自动转换.必须为 Key/Value 格式.如果为数组,jQ ...
- jQuery HTML CSS 方法
jQuery HTML / CSS 方法 下面的表格列出了所有用于处理 HTML 和 CSS 的 jQuery 方法. 下面的方法适用于 HTML 和 XML 文档.除了:html() 方法. 方法 ...
- 原生JS替代jQuery的各种方法汇总
前端发展很快,现代浏览器原生 API 已经足够好用.我们并不需要为了操作 DOM.Event 等再学习一下 jQuery 的 API.同时由于 React.Angular.Vue 等框架的流行,直接操 ...
- jQuery的replaceWith()函数用法详解
replaceWith,替换元素 replaceWith() 方法将选择的元素的内容替换为其他内容. 我们先在先看一个实例 <!DOCTYPE html> <html> < ...
- JavaScript和jQuery中的方法整理
一.属性操作 // JavaScript: Dom.hasAttribute('attrName'); //是否有指定属性 Dom.hasAttributes(); //是否有属性 Dom.getAt ...
- jquery 通过submit()方法 提交表单示例
jquery 通过submit()方法 提交表单示例: 本示例:以用户注册作为例子.使用jquery中的submit()方法实现表单提交. 注:本示例仅提供了对表单的验证,本例只用选用了三个字段作为测 ...
- jquery.on()超级方法
$.on()方法是jquery1.7之后的一个超级方法,将事件绑定和事件委托整合到一个函数中去,支持绑定多个事件,并且可以绑定自定义事件.使用起来很方便. demo传送门 事件委托 首先说一下事件委托 ...
- 重写jquery的ajax方法
//首先备份下jquery的ajax方法 var _ajax=$.ajax; //重写jquery的ajax方法 $.ajax=function(opt){ //备份opt中error和success ...
随机推荐
- Visual Studio 2015 Tools for Unity使用基础
Unity4.x编辑器侧 具体版本号:Visual Studio 2015 Tools for Unity 3.7.0.1 该插件在:Microsoft Visual Studio Tools for ...
- UVA 291 The House Of Santa Claus DFS
题目: In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you re ...
- python asyncio 关闭task
import asyncio import time async def get_html(sleep_times): print("waiting") await asyncio ...
- 第二十二节:Asp.Net Core中使用托管服务实现后台任务
1. 说明 BackgroundService 是用于实现长时间运行的 IHostedService 的基类,使用程序集:Microsoft.Extensions.Hosting. 2. 实现方式 继 ...
- MongoDB官方下载安装设置配置文件指定端口号
1.)下载 官网(https://www.mongodb.com/)右上角try free 进入下载中心,下载指定版本 ZIP和MSI随便 如果浏览器下载的慢,可以直接使用下载地址,然后迅雷下 操作 ...
- Redis 主从同步+哨兵
简介 通过使用 Redis 自带“主从同步+哨兵守护”功能提高Redis稳定性. 主从同步:保障数据主从数据实时同步. 哨兵:实时监控主redis如果故障,将从redis作为主使用. 环境: 系统:C ...
- Ubuntu关机重启后 NVIDIA-SMI 命令不能使用
问题: 电脑安装好Ubuntu系统后,后续安装了显卡驱动.CUDA.cuDNN等软件,后续一直没有关机.中间系统曾经有过升级,这也是问题所在.系统升级导致内核改变,并可能导致它与显卡驱动不再匹配,所以 ...
- C#使用HttpClient上传文件并附带其他参数
HttpClient和MultipartFormDataContent(传送门)最低适用于.NET Framework 4.5版本 发送端代码 using (HttpClient client = n ...
- deepin把vscode设为默认文本应用
一开始我想自己写一个desktop文件放在/usr/share/applications下面,结果在右键菜单里面找不到vscode. [Desktop Entry] Categories=Develo ...
- afnet缓存
http://www.open-open.com/code/view/1432299750333