EDIT: solved with a count variable and if/else.(编辑:用一个计数变量和if / else解决。)
Not the most elegant but it works.(不是最优雅的,但它可以工作。) Would be interesting to know why it happens / how it should be solved though so i'll keep this here.(知道为什么会发生/应该如何解决会很有趣,所以我会在这里保留。)
I have a searchbar with a submit and a dropdown option i am appending to that submit.(我有一个带有提交的搜索栏和一个附加到该提交的下拉选项。) The submit gets appended twice.(提交被追加两次。) I tried using "one" instead of "on" which only returned the first submit.(我尝试使用“一个”代替“打开”,它仅返回第一个提交。) the problem is i need it to only return the second submit or best case prevent the first submit from happening.(问题是我需要它仅返回第二个提交或最好的情况,以防止第一次提交发生。) Currently my url looks like this: "/...?search=test&Item=1&Item=3" and i only want the "&item=3" as the first variable doesn't get updated.(目前,我的网址看起来像这样:“ / ...?search = test&Item = 1&Item = 3”,我只希望“&item = 3”,因为第一个变量不会更新。)
var variableToSend = '';
$('#selector').on('click',function() {
variableToSend = $(this).val();
$('form').append('<input type="hidden" id="yourData" name="Item" value="'+ variableToSend +'"/>');
});
ask by mulraf translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…