我有此功能用于以一种方式工作的窗口之间的值,但不是另一种...
工作脚本:
$(document).ready(function(e) {
$('#clickit').live({
click: function() {
window.opener.document.forms['orderForm']['service'].value = document.forms['GroundRates']['service'].value;
window.opener.document.forms['orderForm']['rate'].value = document.forms['GroundRates']['rate'].value;
self.close();
return false;
}
});
});
现在我在另一个脚本上,我做错了什么?我在这里拔头发。
无法运作:
$(document).ready(function(e) {
$('#clickit').live({
click: function() {
var thisservice = document.forms['GroundRates']['service'].value;
var thisrate = document.forms['GroundRates']['rate'].value;
var thatservice = window.opener.document.forms['orderForm']['service'].value;
var thatrate = window.opener.document.forms['orderForm']['rate'].value;
$(thatrate) = $(thisrate);
$(thatservice) = $(thisservice);
self.close();
return false;
}
});
});
我也尝试过
$(thatrate).val() = $(thisrate).val();
$(thatservice).val() = $(thisservice).val();
和..
thatrate = thisrate;
thatservice = thisservice;
但这有效:
var service = document.forms['GroundRates']['service'].value;
var rate = document.forms['GroundRates']['rate'].value;
window.opener.document.forms['orderForm']['service'].value = service;
window.opener.document.forms['orderForm']['rate'].value = rate;
我没有为
window.opener
正确分配var吗? 最佳答案
var thisservice = document.forms['GroundRates']['service'];
var thisrate = document.forms['GroundRates']['rate'];
var thatservice = window.opener.document.forms['orderForm']['service'];
var thatrate = window.opener.document.forms['orderForm']['rate'];
thatrate.value = thatservice.value;
thatservice.value = thisservice.value;
或者如果您想用jQuery对象包装DOM对象。
var thisservice = document.forms['GroundRates']['service'];
var thisrate = document.forms['GroundRates']['rate'];
var thatservice = window.opener.document.forms['orderForm']['service'];
var thatrate = window.opener.document.forms['orderForm']['rate'];
$(thatrate).val( $(thatservice).val() );
$(thatservice).val( $(thisservice).val() );
关于javascript - Javascript&JQuery奇怪的问题还是我做错了什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8390027/