[英]Odd jQuery Variable-Passing Behavior
我試圖在單擊按鈕時將變量傳遞給隱藏的表單輸入,如下所示:
$('#convertToButton').click(function() {
$("#currencySelectValue").val($("#currencySelect").val());
$("#currencyValue").val($("#fromCurrencyValue").val());
$.post("php/convertToForm.php", $("#convertToForm").serialize(), function(data){
$('#toCurrencyValue').val(data);
});
});
$('#convertFromButton').click(function() {
$("#currencySelectValue").val($("#currencySelect").val());
$("#btcValueForm").val($("#btcValue").val());
$.post("php/convertFromForm.php", $("#convertFromForm").serialize(), function(data){
$('#fromCurrencyValue').val(data);
});
});
在第一個點擊處理程序中,一切都順利通過。 在第二次單擊處理程序中,表單未顯示為已通過#currencySelectValue
。 代碼是一樣的,所以我不確定問題出在哪里。
以下是 forms:
<form action="php/convertToForm.php" id="convertToForm">
<input type="hidden" value="<?php echo $last; ?>" name="lastPrice" id="lastPrice"/>
<input type="hidden" name="currencySelectValue" id="currencySelectValue"/>
<input type="hidden" name="currencyValue" id="currencyValue"/>
<!-- get values of the currency selector, and the currency value -->
</form>
<form action="php/convertFromForm.php" id="convertFromForm">
<input type="hidden" value="<?php echo $last; ?>" name="lastPrice" id="lastPrice"/>
<input type="hidden" name="currencySelectValue" id="currencySelectValue"/>
<input type="hidden" name="btcValueForm" id="btcValueForm"/>
<!-- get values of the currency selector, and the BTC value -->
</form>
除了#currencySelectValue
中的 #currencySelectValue 之外的所有內容都可以正常傳遞。 有什么幫助嗎?
您絕不應該在整個文檔中擁有多個具有相同 ID 的元素。 ID 必須是唯一的才能工作。
如果要 select 副本或類似部分,請改用類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.