当前第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选择器通过class名获取id实例分享
html5和jQuery实现弹出创意搜索框层的方法
jQuery 数组判断值是否存在的方法
jQuery this与$(this)的区别
jQuery ajax区别是什么
jQuery怎么样判断值是否是url地址
jQuery的ajax()函数传值中文乱码怎么办
jQuery primeui是什么?
jQuery如何显示和隐藏元素
jQuery需要下载吗
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jQuery如何选择以特定字符开头的ID元素