我是 jquery 的新手。我知道这个问题很愚蠢,但我在这里遗漏了一些概念。这是问题所在:
$("input.integers").each(function(index) {
console.log("----");
console.log($(this).attr('id') + " " + $(this).val());
console.log($(this).attr('id') + " " + $("#"+$(this).attr('id')).val());
// the next log is here just to show a direct selection. I'm concerned about the two logs above this one
console.log($("#myId").attr('id'), $("#myId").val());
that.setModelData($(this).attr('id'), $(this).val());
});
这是输出:
PhantomJS 1.6 (Linux) LOG: '----'
PhantomJS 1.6 (Linux): Executed 61 of 90
PhantomJS 1.6 (Linux) LOG: 'myId '
PhantomJS 1.6 (Linux): Executed 61 of 90
PhantomJS 1.6 (Linux) LOG: 'myId 123'
PhantomJS 1.6 (Linux): Executed 61 of 90
PhantomJS 1.6 (Linux) LOG: [ 'myId', '123' ]
标签是输入。为什么$(this).val()
是空的并且$("#"+$(this).attr('id')).val()
包含正确的值?
更新:
业力测试:
it('the model must be updated', function(){
$("#myId").val("123");
$("#save-process").click();
server.respond();
expect(fdtView.model.get('myId')).toBe("123");
});
夹具:
<input id="myId" name="myId"
class="integers" type="text" />