jquery ie8 get text value = Object不支持此属性或方法 [英] jquery ie8 get text value = Object doesn't support this property or method
问题描述
我在主div内的两个div内有两个span标签
I have two span tags inside two divs inside a master div
<div>
<div>
<span id="spanA">start text</span>
</div>
<div>
<span id="spanB">start text two</span>
</div>
<div>
我使用jquery 1.7.2并尝试获取页面加载时的默认文本值a& b,然后onclick更改span a&的值b然后在切换时将它们改回来。
在FF / chrome上运行正常但ie8正在抛出错误
I use jquery 1.7.2 and am trying to get the default text value on the page load for span a & b, then onclick change the value of span a & b and then on toggle change them back. On FF/chrome this works fine but ie8 is throwing an error
Object doesn't support this property or method
onload
spanAval = $('#spanA').text();
spanBval = $('#spanB').text();
onclick
$('#spanA').text("replace text");
$('#spanB').text("replace text two");
onToggle
$('#spanA').text(spanAval);
$('#spanB').text(spanBval);
在ie8中文本被替换为[object]
in ie8 the text is replaced with "[object]"
我确信我遗漏了一些基本的东西,
谢谢
艺术
I am sure I am missing something basic, thanks Art
推荐答案
好吧,这是基本的东西,我有一个相同的名称为var
ok it was something basic, I had the same name for the var as the id
spanA = $('#spanA').text();
它在ie8中失败但在其他浏览器FF / chrome等中工作,通过更改var名称在ie8中使用的唯一名称
and it failed in ie8 but worked in the other browsers FF/chrome etc , by changing the var name to a unique name it works in ie8
spanAval = $('#spanA').text();
thx快速回复
这篇关于jquery ie8 get text value = Object不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!