jquery对元素操作,获取/替换文本(.text())、html(.html())、属性(.attr())、值(.val())

 

html代码

测开之路一百零二:jquery元素操作

 

text()

根据标签获取文本值

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

同一个标签下筛选明细

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

最后一个元素

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

第一个元素

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

替换文本

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

 

html

获取html

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

 替换html

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>元素操作</title>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
</head>
<body>
<button ).html();
//alert(str);
});
});
</script>

 

属性(.attr())

html代码

测开之路一百零二:jquery元素操作

 

获取a标签的href属性

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

获取img标签的alt属性

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

修改属性

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

修改多个属性

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery 属性操作</title>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<style>
.bdr{
border: 5px solid #000;
padding: 5px;
}
</style>
</head>
<body>
<h1>获取/改变/增加属性:attr("属性")</h1>
<button ); //获取属性
// alert(str);
// });
});
</script>

 

值(.val())

测开之路一百零二:jquery元素操作

 

获取值

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

插入html

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

 

把值插入到指定位置

测开之路一百零二:jquery元素操作

测开之路一百零二:jquery元素操作

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery 获取/改变/增加 值</title>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
</head>
<body>

<table>
<tr>
<td>姓名:</td>
<td><input type="text" ).html(content);


});
});
</script>

 

相关文章:

  • 2021-12-20
  • 2021-12-03
  • 2021-10-31
  • 2021-11-30
  • 2021-08-13
  • 2021-07-24
猜你喜欢
  • 2021-06-29
  • 2021-11-13
  • 2021-12-09
  • 2021-10-16
  • 2021-07-29
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案