快捷方式後運行功能,試試這個小提琴: http://jsfiddle.net/purushagovinda/VJfkx/的jQuery如何只更新隱藏的輸入值
我的jQuery代碼塊,我想得對,使其設置的值隱藏的輸入元素(從value="keywords"
更改爲value="furniture"
)和然後調用函數(「refresh_itemListerWithSearchResultsReturn();
」),該函數將ajax調用中的主div的內容重新加載到另一個文件 - 依賴於隱藏輸入值的文件。
我的代碼現在成功地設置了隱藏輸入的值,然後在觸發時觸發該功能,但是該功能仍認爲隱藏的輸入值=「關鍵字」。這讓我覺得我要做到這一點:
$("#myHiddenInput").val('furniture');
...但如果該行^^^有一個回調函數,我堅持內的refresh_itemListerWithSearchResultsReturn()
函數調用的.VAL()回調。所以,作爲一個相對的小白,我這裏一看,
...但看不出有如何使用.val();
一個回調函數。該文檔頁面上的示例顯示.val()
帶有函數調用,但該函數用於確定val()
將用於該值本身,而不是像我需要的那樣觸發回調。
任何建議我如何着手?
的代碼實際上是這樣的:
$("#products_furniture_furnitureType_options > li").each(function() {
$(this).click(function(e) {
[snip]
$("#dp_searchForWhichItemType_listRefresh").val('products');
$('#bit_products_productType').val('furniture');
$("#bit_products_productType").val("furniture").change(function(){
alert("'#bit_products_productType' is changed now 2");
$.refresh_itemListerWithSearchResultsReturn('itemList', false, false);
});
[snip]
});
});
我也試過這樣:
$("#products_furniture_furnitureType_options > li").each(function() {
$(this).click(function(e) {
[snip]
$("#dp_searchForWhichItemType_listRefresh").val('products');
$('#bit_products_productType').val('furniture');
$("#bit_products_productType").change(function(){
alert("'#bit_products_productType' is changed now 2");
$.refresh_itemListerWithSearchResultsReturn('itemList', false, false);
});
[snip]
});
});
...也試過$('#bit_products_productType').val('furniture');
之前移動$("#bit_products_productType").change(function(){
到...
...但在任何情況下alert("'#bit_products_productType' is changed now 2");
不會觸發。
這應該可以幫助你們專注,並且能夠幫助我: http://jsfiddle.net/purushagovinda/VJfkx/
你能在這裏展示你的完整代碼嗎? –
java-script在一個線程上運行。如果你在下一行啓動重載功能,你可以確定這個值已經更新了 – Josh
目前還不清楚你想要達到的目標,但是爲什麼你不把revalResults函數中的新值作爲參數傳遞? – Vassilis