jQuery Selector:ID以结束吗? [英] jQuery Selector: Id Ends With?

查看:63
本文介绍了jQuery Selector:ID以结束吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查询selector具有以给定字符串结尾的ID的元素?

Is there a selector that I can query for elements with an ID that ends with a given string?

说我有一个ID为ctl00$ContentBody$txtTitle的元素.如何通过仅传递txtTitle来获得此信息?

Say I have a element with an id of ctl00$ContentBody$txtTitle. How can I get this by passing just txtTitle?

推荐答案

如果您知道元素类型,则:(例如:将'element'替换为'div')

If you know the element type then: (eg: replace 'element' with 'div')

$("element[id$='txtTitle']")

如果您不知道元素类型:

If you don't know the element type:

$("[id$='txtTitle']")

更多可用信息

// the old way, needs exact ID: document.getElementById("hi").value = "kk";
$(function() {
  $("[id$='txtTitle']").val("zz");
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="ctl_blabla_txtTitle" type="text" />

这篇关于jQuery Selector:ID以结束吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆