如何选择当前 DIV ID 以使用该 ID 运行 Jquery
How to select current DIV ID to run Jquery with that ID?
我有这样的HTML。
<div id="content"
<div id="widget1">
<script type='text/javascript'>
jQuery("#widget(current)").selectme({
Numpost:4,
Stylepost:"papa",
});
</script>
</div>
<div id="widget89">
<script type='text/javascript'>
jQuery("#widget(current)").selectme({
Numpost:7,
Stylepost:"popo",
});
</script>
</div>
..............
<div id="widget(anyIndex)">.....</div>
</div>
当我添加更多时,小部件 ID 会更改。例如:widget89 设置为当前,但我不知道该 widget 的索引(index = 89),只是确定我正在将 Javascript/Jquery 代码输入其中。当我添加新的小部件时,我将有新的索引,例如:widget105或widget200(anyindex)。
每当我添加更多用于在内部运行 Jquery 时,如何捕获当前小部件。这意味着我们有同样的事情,例如:
<div id="widget1">
<script type='text/javascript'>
jQuery("#widget1").selectme({
Numpost:4,
Stylepost:"papa",
});
</script>
</div>
<div id="widget89">
<script type='text/javascript'>
jQuery("#widget89").selectme({
Numpost:7,
Stylepost:"popo",
});
</script>
</div>
尝试使用属性开始选择器,例如,
jQuery( "[id^='widget']" ).selectme({
或者您可以为您的element
申请class
,例如,
<div class="select-me-widget">.....</div>
并用于jquery
,例如,
jQuery( ".select-me-widget" ).selectme({
相关文章:
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 获取打开jquery对话框的button的id
- jQuery mobile not going through ID
- 如何将li类更改为li id's在Jquery中
- 如何使用jQuery迭代id名称的变体(如idname1、idname2)
- 获取不带Id JQuery的复选框值
- 从ID Jquery类获取返回值时出现问题
- attr() 不会更改 id - jquery
- 通过 ID jquery 限制文本区域字符
- 获取选定的行id jquery数据表行选择
- 如何在asp.net mvc中向Action方法发布简单ID(jquery-ajax)
- 添加文本到Javascript Span id jquery
- 动态获取控件ID - JQuery
- 验证选择字段取决于id jquery
- Increment id jquery
- 使用id jquery中的空格
- 根据HTML表的ID jQuery/javaScript对数据进行排序
- 以引号结束id - jquery
- 当draggable被拖放到可拖放区域时添加ID - jQuery Draggables
- 表格ID &jQuery中的名称