我有一个对话框,需要依赖三个输入字段进行计算。当它们中的任何一个被更改时,它都会检查它们是否都已填写并进行处理并给出响应。
在 Firefox、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时才会触发。
.click()
而不是.change()
。 - jfriend00<85
。 - Guffa