I have the following html:
我有以下html:
<html>
<head></head>
<body>
<form>
<input id="msg" type="text" value="oldValue" />
</form>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script>
$().ready(function() {
var m = $("#msg");
alert(m.val()); // returns oldValue
m.val("newValue"); // this doesn't make the browser show newValue instead of oldValue
alert(m.val()); // returns newValue
// and in the end, the browser still shows oldValue for the input
});
</script>
</body>
</html>
This code runs perfect, but when placed in a facebox (which just creates an iframe and shows it like a floating window), the code fails to update the input's content.
此代码运行完美,但是当放置在facebox(它只是创建iframe并将其显示为浮动窗口)时,代码无法更新输入的内容。
The parent also has jQuery, but that shouldn't influence anything I guess.
父母也有jQuery,但这不应该影响我猜的任何东西。
Any ideas why it's failing?
任何想法为什么失败?
2 个解决方案
#1
1
Unable to replicate on Firefox 3, IE 7 or Chrome 2. The code works fine (using newValue
everywhere appropriate) regardless of whether it's in an iframe.
无法在Firefox 3,IE 7或Chrome 2上进行复制。代码工作正常(在适当的地方使用newValue),无论它是否在iframe中。
Have you tested your reduced sample implementation, as opposed to your original? Because I suspect we have a problem where you think they're equivalent and they aren't.
您是否测试过减少的样本实施,而不是原始实施?因为我怀疑我们遇到了一个问题,你认为它们是等价的而不是。
Of course, the good news is that if your posted sample implementation works, then all you have to do is add in elements from your actual implementation until something breaks.
当然,好消息是如果您发布的示例实现有效,那么您所要做的就是从实际实现中添加元素,直到出现问题。
#2
-1
doc = xframe.contentWindow.document || xframe.document || xframe.contentDocument || xframe.contentWindow && xframe.contentWindow.document || null;
if(!doc)
{
alert("Error");
return false;
}
var m = $(doc).find("#msg");
#1
1
Unable to replicate on Firefox 3, IE 7 or Chrome 2. The code works fine (using newValue
everywhere appropriate) regardless of whether it's in an iframe.
无法在Firefox 3,IE 7或Chrome 2上进行复制。代码工作正常(在适当的地方使用newValue),无论它是否在iframe中。
Have you tested your reduced sample implementation, as opposed to your original? Because I suspect we have a problem where you think they're equivalent and they aren't.
您是否测试过减少的样本实施,而不是原始实施?因为我怀疑我们遇到了一个问题,你认为它们是等价的而不是。
Of course, the good news is that if your posted sample implementation works, then all you have to do is add in elements from your actual implementation until something breaks.
当然,好消息是如果您发布的示例实现有效,那么您所要做的就是从实际实现中添加元素,直到出现问题。
#2
-1
doc = xframe.contentWindow.document || xframe.document || xframe.contentDocument || xframe.contentWindow && xframe.contentWindow.document || null;
if(!doc)
{
alert("Error");
return false;
}
var m = $(doc).find("#msg");