问题我有这个JS,由于某些原因,它不能在IE或Chrome中工作,但它在FF中工作,帮助将是不胜感激。似乎无法弄清楚为什么我的JavaScript不工作在IE和Chrome
附注我需要这是一些奇怪的原因点击功能的变化function--在IE和Chrome,但在这种情况下,我需要的是一个变化,这也是一个RubyRails应用。
这里是我的代码..
$(document).ready(function() {
$('#emp_id').change(function() {
var url = "/user/populate_form?emp_id=" + $(this).val();
$.getJSON(url, function (data) {
if (!(data.emp_first_name === undefined))
$('#emp_first_name').val(data.emp_first_name);
if (!(data.emp_last_name === undefined))
$('#emp_last_name').val(data.emp_last_name);
if ((data.error * 1) == 404) {
alert("The employee ID entered was not found!");
} else {
window.confirm("Your employee ID was found please fill in the email(optional) and password fields then click the sign in button to register.");
}
});
});
});
我也试过这仍然没有在IE &使用的Chrome
$(document).ready(function() {
$('#emp_id').on('change', function() {
var url = "/user/populate_form?emp_id=" + $(this).val();
$.getJSON(url, function (data) {
if (!(data.emp_first_name === undefined))
$('#emp_first_name').val(data.emp_first_name);
if (!(data.emp_last_name === undefined))
$('#emp_last_name').val(data.emp_last_name);
if ((data.error * 1) == 404) {
alert("The employee ID entered was not found!");
} else {
window.confirm("Your employee ID was found please fill in the email(optional) and password fields then click the sign in button to register.");
}
});
});
});
想这也仍然在IE和Chrome
没有工作$(document).ready(function() {
$('#emp_id').keyup('onchange', function() {
var url = "/user/populate_form?emp_id=" + $(this).val();
$.getJSON(url, function (data) {
if (!(data.emp_first_name === undefined))
$('#emp_first_name').val(data.emp_first_name);
if (!(data.emp_last_name === undefined))
$('#emp_last_name').val(data.emp_last_name);
if ((data.error * 1) == 404) {
alert("The employee ID entered was not found!");
} else {
window.confirm("Your employee ID was found please fill in the email(optional) and password fields then click the sign in button to register.");
}
});
});
});
这是我的看法代码
<div class='row form-group'>
<div class='col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 col-lg-2 col-lg-offset-5 text-right'>
<%= f.text_field :emp_id, tabindex: 1, id: 'emp_id', autofocus: true, placeholder: t('login_label'), class: 'form-control' %>
</div>
</div>
<div class='row form-group'>
<div class='col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 col-lg-2 col-lg-offset-5 text-right'>
<%= f.text_field :emp_first_name, tabindex: 1, id: 'emp_first_name', autofocus: true, placeholder: t('login_label'), class: 'form-control' %>
</div>
</div>
<div class='row form-group'>
<div class='col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 col-lg-2 col-lg-offset-5 text-right'>
<%= f.text_field :emp_last_name, tabindex: 1, id: 'emp_last_name', autofocus: true, placeholder: t('login_label'), class: 'form-control' %>
</div>
</div>
什么是不正确的工作?更改事件是否被触发? Ajax调用是否正在进行?处理Ajax调用是否存在错误(又名https://api.jquery.com/ajaxError/)您将需要调试此操作。 – epascarello
该警报是一个自定义警报,我只是使用确认,因为我是懒惰,并希望创建分开警报框大声笑。 @ epascarello – Snowman1234
它似乎是改变功能不工作,因为当我改变它点击它的作品和AJAX的作品,所以我很确定它与改变功能有关。 @epascarello – Snowman1234