在 Google Chrome 和 Internet Explorer 中选择字段中的选项时,触发 ajax 响应不起作用。但它确实适用于所有其他浏览器。
这是 html:
<select>
<option class="showDiv" data-div="0,1,0,mw1,default" data-vars="2136,1|10|1|0" selected="">added</option>
<option class="showDiv" data-div="0,1,0,mw1,default" data-vars="2136,1|10|1|1">title</option>
</select>
这是 ajax 部分:
$('.showDiv').live("click", function () {
var divs = $(this).attr('data-div');
var vars = $(this).attr('data-vars');
divs = divs.split(",");
$.ajax({
type: "post",
url: "crt/run_script.php",
data: {
divs: divs,
vars: vars,
},
beforeSend: function () {
centerWin("loading");
},
complete: function () {
$("#loading").hide("fast");
},
success: function (html) {
$("#mainWin").html('');
$("#mainWin").html(html);
}
});
});
最佳答案
为什么不这样做而不是改变选择元素呢?
$('#selectID').change(function(){
...
});
<小时/>
要获取所选的选项,您可以执行以下操作:
$('#selectID').change(function(){
var index = this.selectedIndex;
var option = $(this.options[index]);
//rest of the code use `option` instead of `this` in your code
...
});
关于jquery - 在 Google Chrome 中选择选择字段中的选项不会触发 ajax 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7404997/