当前第2页 返回上一页
示例:选择id以“demo”开头的元素并更改其背景颜色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <!DOCTYPE html>
<html>
<head>
<meta charset= "utf-8" >
<style>
#demo_div {
background: green;
height: 100px;
width: 200px;
margin: 0 auto;
color: white;
line-height: 100px;
}
</style>
<script src= "https://code.jquery.com/jquery-1.10.2.js" ></script>
</head>
<body style = "text-align:center;" >
<div id = "demo_div" > 这是div盒。</div>
<p id = "demo_p" style = "font-size: 19px; font-weight: bold;" ></p>
<button onClick = "GFG_Fun()" >点击这里</button>
<p id = "demo_DOWN" style = "color: white; font-size: 24px; font-weight: bold;" > </p>
<script>
$( '#demo_p' ).text( "点击按钮,选择id以“demo”开头的元素并更改背景色。" );
function GFG_Fun() {
$( "[id^='demo']" ).css( "background-color" , "pink" );
$( '#demo_DOWN' ).text( "测试文字!" );
}
</script>
</body>
</html>
|
输出:
相关免费学习推荐:javascript(视频)
以上就是jQuery如何选择以特定字符开头的ID元素的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
jQuery怎么删除html元素
使用jQuery怎么获取url参数?
jQuery javascript ajax区别是什么
不同的jQuery版本冲突怎么办
ajax与jQuery的区别是什么
jQuery发请求传输中文参数乱码怎么办
jQuery和document获取html元素的区别是什么?
如何用jQuery实现随机数
jQuery怎么移除css样式
jQuery怎么去除css属性
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jQuery如何选择以特定字符开头的ID元素