[英]Why does calling a function onclick not work all the time in Chrome and FF, but works in IE?
[英]Select option onclick function works in FF but not in Chrome
我可以在firefox中成功更改圖表選項,但它在chrome中不起作用(沒有錯誤)。 我已經閱讀了關於這個問題的幾乎所有主題,但它們都沒有為我工作。 當用戶選擇選項時,捕獲的正確方法是什么?
<select id="sortby2">
<option id="byweek" value="date">7 days</option>
<option id="by14" value="spent">14 days</option>
<option id="bymonth" value="clicks">30 days</option>
</select>
$("#by14").OnClick(function(){
$.ajax({
type: "POST",
url: "chartdata.php",
data: 'by14=on',datatype:"html", async: false,
success: function(d){
$('.cantent').html(d);
}
});
});
您可能需要使用change()而不是click
事件。
$("#sortby2").change(function(){
if($(this).find('option:selected')[0].id != 'by14')
return;
$.ajax({
type: "POST",
url: "chartdata.php",
data: 'by14=on',datatype:"html", async: false,
success: function(d){
$('.cantent').html(d);
}
});
});
在select元素上偵聽“change”事件。 最好使用jQuery on()函數來注冊它:
$("#sortby2").on('change', function(){
if($(this).val() === 'spent') {
$.ajax({
type: "POST",
url: "chartdata.php",
data: 'by14=on',datatype:"html", async: false,
success: function(d){
$('.cantent').html(d);
}
});
}
});
使用$("#by14").click
不是$("#by14").onclick
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.