如何从 href 属性获取默认 id 值
How to get the default id value from an href attribute
这是我动态创建输入框的代码片段:
if (data != null) {
locations = data;
for (var i = 0; i < locations.length; i++) {
var newLineItem = domEditor.CreateElement({ type: "li" });
var roomsLink = domEditor.CreateElement({ id: locations[i].Id, name: "locationRadioBtns", type: "a", href: "#", onclick: self.SelectLocation, innerHtml: locations[i].DisplayName, checked: i == 0, parent: $("#LocationRadioButtons") });
$(newLineItem).append(roomsLink);
$(LocationRadioButtons).append(newLineItem);
}
self.Display();
}
显示方法,我需要获取 href 标签创建的第一个元素的 id
this.Display = function () {
console.log($('#locationRadioBtns').val(0)); //value of your default option
};
它以未定义返回
你想要循环创建的第一个元素的id
-属性吗?
尝试
console.log($('#locationRadioBtns a').first().attr('id'));
相关文章:
- 用嵌套函数和默认函数定义函数
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- 使用Javascript获取所选选项ID
- 根据id将json数组组合为一个json数组
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 如何使用铁流星与流星的默认路线
- 防止Alt+Shift默认操作或检测多种操作系统语言的Javascript
- 对id以某个字符串开头的元素进行计数
- 获取从默认设置更改的所有复选框的 id
- 如何从 href 属性获取默认 id 值
- 如何设置具有可选ID的路由以进行查找,以及回退默认模型
- angularjs选择框基于数据库id的默认选择
- AngularJS通过嵌套的id属性来设置单选按钮数组的默认值
- 如何设置ngOptions的默认值,当options是对象时,default是一个整数ID
- Angular.js:从ID中选择默认值
- 索引" id"In couchdb默认存在
- 在jQuery中为特定ID或整个项目设置“无默认排序”(“aaSorting”:[])
- 使 id 链接可见 - 防止单击定位点时发生默认事件
- JQuery对话框-添加和ID默认关闭链接("X"图标)