innerHTML替换不反映 [英] innerHTML replace does not reflect

查看:109
本文介绍了innerHTML替换不反映的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似这样的HTML

I have HTML something like this

<div id="foo">
<select>
<option> one </option>
</select>
</div>

当我使用

document.getElementById('foo').innerHTML = document.getElementById('foo').innerHTML.replace("<option> one </option>", "<option> two </option>") ;

innerHTML被替换但它没有反映在浏览器中。

The innerHTML get replaced but it does not get reflected in the browser.

如果我提醒innerHTML我可以看到它现在已被更改但在浏览器中它仍显示旧选项。

If I alert innerHTML I can see that it has been changed now but in the browser it still shows old option.

有没有办法是否允许浏览器识别此更改?

Is there any way to make this change recognized by the browser ?

提前致谢。

推荐答案

在Firefox 3.5中适合我。

works fine for me in Firefox 3.5

工作演示

Working Demo

编辑:您必须使用IE浏览器。您需要创建一个新选项并将其添加到元素中,或修改现有选项的文本

You must be using IE. You need to create a new option and add it to the element, or amend the text of the existing option

工作演示 - 在FireFox和IE 7中测试并工作。

Working Demo - tested and working in FireFox and IE 7.

var foo = document.getElementById('foo');
var select = foo.getElementsByTagName('select');
select[0].options[0].text = ' two ';

这篇关于innerHTML替换不反映的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆