[英]jQuery .change() event not firing in IE
我有一個對話框執行依賴於三個輸入字段的計算。 當它們中的任何一個被更改時,它會檢查它們是否全部被填充,如果它們是進程並給出它的響應。
它在FF,Chrome,Opera等中運行得非常好,但在任何版本的IE中它都會停止工作。 我的其余jQuery工作正常,但我無法確切地解決問題所在。 我認為它可能與.change()事件或多事件綁定有關,但我真的不知道。
這是有問題的代碼:
var loan = $("#ltv-loan-amount");
var mortgage = $("#ltv-mortgage");
var property = $("#ltv-property");
$("#ltv-dialog input").change( function() {
if(loan.val() && mortgage.val() && property.val())
{
var ltv = parseInt( ( ( parseInt(loan.val()) + parseInt(mortgage.val()) ) / parseInt(property.val()) )* 1000 );
ltv /= 10;
if(ltv > 0 && ltv < 85)
{
$("#ltv-result").html("<span id=\"ltv-form-result\">" + ltv + "%</span></p><p><a id=\"ltv-link\" href=\"#sidebar-head\">Congratulations, your LTV has passed. Please now proceed with your application opposite.</a>");
$("#amount").val(loan.val());
$("#mortgage_balance").val(mortgage.val());
$("#prop_value").val(property.val());
$("#ltv-link").click(function() {
$( "#ltv-dialog" ).dialog( "close" );
});
}
else if (ltv > 84)
{
$("#ltv-result").html("<span id=\"ltv-form-result\">" + ltv + "%</span></p><p>Unfortunately your LTV is greater than 85%. You may still qualify for a loan if you reduce the loan amount.");
}
else
{
$("#ltv-result").html("</p><p>Please check your input above as you currently have a negative ltv.");
}
}
});
和有問題的HTML:
<div id="ltv-dialog" title="Do You Qualify for a Loan?">
<p>Please enter the fields below and your LTV will be calculated automatically.</p>
<div id="ltv-form">
<div class="ltv-row">
<label for="ltv-loan-amount">Loan Amount:</label>
<input type="text" name="ltv-loan-amount" id="ltv-loan-amount" class="p000" />
</div>
<div class="ltv-row">
<label for="ltv-mortgage">Mortgage Value:</label>
<input type="text" name="ltv-mortgage" id="ltv-mortgage" class="p000" />
</div>
<div class="ltv-row">
<label for="ltv-property">Estimated Property Value:</label>
<input type="text" name="ltv-property" id="ltv-property" class="p000" />
</div>
</div>
<div class="ltv-row">
<p>Loan to Value % (LTV): <span id="ltv-result"></span></p>
</div>
</div>
更新
更改事件似乎是觸發,但僅當文本框從值更改為null時。
在定位文本輸入元素時,您是否嘗試過使用其他事件? 所以,而不是change
使用,例如, keyup
? $("#ltv-dialog input").keyup( function() {
。這將在每次按鍵后觸發。
使用jQuery .on()
也可以解決您的問題。 像這樣使用它:
jQuery("#ltv-dialog").on("change", "input", function(){
alert("It works !");
//your javascript/jQuery goes here
}
);
我遇到了同樣的問題:以下修復對我有用:
而不是: $("#ltv-dialog input").change( function() {
我用過: $('#ltv-dialog').on('input', function() {
請嘗試使用每個而不是更改 / 單擊 ,這在IE和其他瀏覽器中首次工作正常
不是第一次工作
$("#checkboxid").change(function () {
});
第一次工作正常
$("#checkboxid").each(function () {
});
使用實時功能,它通常使它工作...
$("#YOURTHING").live("change", function(){
// CODE HERE
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.