問題我有這個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