jquery获取单击按钮值并将其发送到listbox 我需要点击按钮值并将其发送到ListBox。下面是我的代码,我在代码的中间进行注释,我需要得到点击按钮的值并将其发送到ListBox <asp:ListBox ID="ListBox2" runat="server"></asp:ListBox> $(function () { var count = 0; $('input[type=button]').on('click', function (e) { e.preventDefault(); count += 1; if (count % 2 === 0) { $(this).css('background-color', '#6FA478'); //I have to get here the value of every click button and send it to listbox } else { $(this).css('background-color', ''); } }); }); $(函数(){ var计数=0; $('input[type=button]')。在('click',函数(e){ e、 预防默认值(); 计数+=1; 如果(计数%2==0){ $(this.css('background-color','#6FA478'); //我必须在这里得到每个点击按钮的值,并将其发送到listbox } 否则{ $(this.css('background-color',''); } }); });
在有评论的地方试试这个jquery获取单击按钮值并将其发送到listbox 我需要点击按钮值并将其发送到ListBox。下面是我的代码,我在代码的中间进行注释,我需要得到点击按钮的值并将其发送到ListBox <asp:ListBox ID="ListBox2" runat="server"></asp:ListBox> $(function () { var count = 0; $('input[type=button]').on('click', function (e) { e.preventDefault(); count += 1; if (count % 2 === 0) { $(this).css('background-color', '#6FA478'); //I have to get here the value of every click button and send it to listbox } else { $(this).css('background-color', ''); } }); }); $(函数(){ var计数=0; $('input[type=button]')。在('click',函数(e){ e、 预防默认值(); 计数+=1; 如果(计数%2==0){ $(this.css('background-color','#6FA478'); //我必须在这里得到每个点击按钮的值,并将其发送到listbox } 否则{ $(this.css('background-color',''); } }); });,jquery,Jquery,在有评论的地方试试这个 var value = $(this).val(); $("[id$=ListBox2]").append('<option value="'+value+'">'+value+'</option>'); var value=$(this.val(); $(“[id$=ListBox2]”。追加(“”+value+“”); 所以代码应该是这样的 $(function () { var count = 0; $('input[ty
var value = $(this).val();
$("[id$=ListBox2]").append('<option value="'+value+'">'+value+'</option>');
var value=$(this.val();
$(“[id$=ListBox2]”。追加(“”+value+“”);
所以代码应该是这样的
$(function () {
var count = 0;
$('input[type=button]').on('click', function (e) {
e.preventDefault();
count += 1;
if (count % 2 === 0) {
$(this).css('background-color', '#6FA478');
//I have to get here the value of every click button and send it to listbox
var value = $(this).val();
$("[id$=ListBox2]").append('<option value="'+value+'">'+value+'</option>');
}
else {
$(this).css('background-color', '');
}
});
});
$(函数(){
var计数=0;
$('input[type=button]')。在('click',函数(e){
e、 预防默认值();
计数+=1;
如果(计数%2==0){
$(this.css('background-color','#6FA478');
//我必须在这里得到每个点击按钮的值,并将其发送到listbox
var值=$(this.val();
$(“[id$=ListBox2]”。追加(“”+value+“”);
}
否则{
$(this.css('background-color','');
}
});
});
尝试此操作以获取当前单击的按钮值
$(this).val();
或
我看不到列表框中的值,但我点击更多的按钮,列表框的滚动条就会出现,就像不可见的值留在那里一样
this.value