gpt4 book ai didi

Javascript 和 JQuery 奇怪的问题或者我做错了什么?

转载 作者:行者123 更新时间:2023-11-28 13:55:11 25 4
gpt4 key购买 nike

我有这个函数来处理从一个窗口到另一个窗口的值,它以一种方式工作,但不是另一种......

工作脚本:

$(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正确分配变量?

最佳答案

您滥用了 .val()

$(thatrate).val($(thisrate).val());
$(thatservice).val($(thisservice).val());

新值位于括号内。

关于Javascript 和 JQuery 奇怪的问题或者我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8390027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com