Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 让jQuery和Ajax更新变量_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 让jQuery和Ajax更新变量

Javascript 让jQuery和Ajax更新变量,javascript,jquery,ajax,Javascript,Jquery,Ajax,我的页面在显示日期和价格表时遇到了另一个jQuery问题。本页的相关部分为 <table align="center" width="100%" style="margin-top:6px"> <tr> <td width="178"> <form name="StartDateCal" id="StartDateCal"> <input type="hidden" name="hid" id="hid" value="<?php ec

我的页面在显示日期和价格表时遇到了另一个jQuery问题。本页的相关部分为

<table align="center" width="100%" style="margin-top:6px">
<tr>
<td width="178">
<form name="StartDateCal" id="StartDateCal">
<input type="hidden" name="hid" id="hid" value="<?php echo $hid ?>">
From &nbsp;&nbsp;<input type="text" id="pricePicker" size="15" value="<?php echo date("D, j M Y",strtotime($startdate)) ?>"> 
<input type="hidden" name="StartDate" id="StartDate">
<input type="hidden" name="defaultdate" id="defaultdate" value="<?php echo $startdate ?>">
<input type="text" name="currency" id="currency">
/*Change to "hidden" after debugging*/
</form>
</td>
<td class="prev">
<a href="#" id="previous"><< Previous</a>
</td>
<td style="padding:0 0 5px 0"></td>
<td class="prev" style="text-align:right">
<a href="#" id="next">Next >></a>
</td>
</tr>
</table>
<div id="pricePickerResult"><br><img src="../images/ajax_loader_blue_64.gif" width="64" height="64" alt="Loading ..."><br><br></div>
<div style="float:right; line-height:18px">Change currency: <a href="#" id="euro"><img src="/images/price.png"></a> <a href="#" id="pound"><img src="/images/price_gbp.png"></a> <a href="#" id="dollar"><img src="/images/price_usd.png"></a></div>
这会更改表(calendar_price.php)的内容,但我需要将变量“curr”的新值反馈给父页面。据我估计

$("#currency").value = 'EUR';
应该这样做,但事实并非如此。其目的是更改默认货币,以便用户可以更改货币,然后更改日期,而不必每次跳回原始货币


我尝试使用变量“curr”代替硬值“EUR”,并尝试使用$(“input#currency”)代替$(“currency”)但是这些东西都没用。这让我分心,但我怀疑这真的很简单。如果你能看完这个长问题,我会非常感激你的想法。谢谢。

你试过
$(“#货币”).val('EUR');
?这是文档页:。
$(“#货币”)
返回jQuery对象,与本机DOM元素不同,您不能通过更改
value
属性来设置值。
.value
不适用于jQuery对象。由于
$(“#currency”)
是一组元素,您可以像这样提取HTML元素:
$(“#currency”)[0].value='EUR';
但是最好使用@Joe的建议。当你知道的时候,这不是很容易吗?Joe的回答很有效。而且这比我问这个问题所花的时间都要少!多亏了你们两个。不幸的是,由于你是通过评论而不是回答来回答的,我不能给它一个大的绿色勾号。
// Change currency to Euros, load ajax
$('a#euro').click(function () {
    var data = $('#StartDateCal').serializeArray();
    data.push({name: 'currency', value: 'EUR'});
        $.ajax ({
        type: 'post',
        url: '/includes/calendar_price.php',
        data: data,
        success: function(result) {
            $("#pricePickerResult").html(result);
        }
    });
$("#currency").value = 'EUR';
    return false;
});
$("#currency").value = 'EUR';