如何使用jQuery

时间:2017-04-23 22:50:36

标签: javascript jquery

我试图获得部门的id值。我的意思是我需要从元素中获取departmentID

此函数获取具有departmentName作为类的元素的输入值。

this.$el.find(".departmentName").val()

示例jSON

{
  "departmentID": 1,
  "departmentName": "BT"
},

来自BackboneJS视图回调的代码

saveEvent:function(e){
  this.$el.find(".departmentName").val(); // getting "BT"
  this.$el.find(".departmentName").attr("departmentID");//this is not working

  this.render();
},

模板

<th>
    <span>{{user.department.departmentName}}</span>
    <input data-placement="top" 
           data-id="{{user.department.departmentID}}" 
           title="Boş geçilemez!" 
           class="form-control text-center departmentName" 
           type='text'
           style='display: none;' 
           value='{{user.department.departmentName}}'/>
</th>

1 个答案:

答案 0 :(得分:2)

使用

this.$el.find(".departmentName").data("id");