0

我想比较两个元素块,看看它们是一样的。我要比较的项目有隐藏的输入,我遇到了这个错误,我认为这与隐藏的输入有关:

TypeError:在无法选择的输入元素上访问 selectionDirection。

这是我的代码的简化版本(以及 JSFiddle 中的内容):

test("compare input", function() {
  var input1 = $('<input/>').attr("value", 'cool_play');
  var input2 = $('<input/>').attr("value", 'cool_play');
  deepEqual(input1, input2);
});

test("compare hidden input", function() {
  var input1 = $('<input/>').attr("type", "hidden").attr("value", 'cool_play');
  var input2 = $('<input/>').attr("type", "hidden").attr("value", 'cool_play');
  deepEqual(input1, input2);
});​

第一个示例通过,但第二个示例引发错误。

这是 jsfiddle 示例:http: //jsfiddle.net/HLG5y/1/

有没有办法将输入元素与隐藏类进行比较?我是否以错误的方式尝试此操作?谢谢你。我觉得我也应该能够比较隐藏的输入。

4

1 回答 1

1

这不是一个理想的解决方案,但我通过比较解决了这个问题

equal(actual.html(), expected.html());

其中实际和预期是元素块。

于 2012-12-21T21:44:01.250 回答