在我的视图中,我有一些下拉列表和一个与document.ready函数中的jQuery函数绑定的输入。
<div class="form-group">
<label><strong>Post-Mitigation RAC</strong></label>
<div>
<label class="rac">Severity</label>
<select id="postRacSeverity" asp-for="PostSeverity">
<option value="">- Select -</option>
<option value="Catastrophic">Catastrophic</option>
<option value="Critical">Critical</option>
<option value="Moderate">Moderate</option>
<option value="Negligible">Negligible</option>,
</select>
</div>
<div>
<label class="rac">Probability</label>
<select id="postRacProbability" asp-for="PostProbability">
<option value="">- Select -</option>
<option value="LikelyToOccur">Likely to occur</option>
<option value="ProbablyWillOccur">Probably will occur</option>
<option value="MayOccur">May occur</option>
<option value="UnlikelyToOccur">Unlikely to occur</option>
<option value="Improbable">Improbable</option>
</select>
</div>
<div>
<label class="rac">Post-Mitigation RAC:</label>
<div><span asp-validation-for="PostRac" class="text-danger"></span></div>
<input class="rac"id="postRac" type="number" asp-for="PostRac" value="" readonly />
</div>
</div>
jQuery的:
$('#postRac').on('input', function () {
getRiskAcceptor(); //will not fire in Chrome but works in IE
});
$('#OfficeID').change(function () {
getRiskAcceptor(); //fires in both Chrome and IE
});
当选择#postProbability和#postSeverity的不同下拉组合时,有javascript会更改postRac输入值。 getRiskAcceptor()用于获取JSON对象并返回与name / email对应的字符串。该功能在IE中运行良好,但在Chrome中无效。
我已经尝试过以下多种方式让它在Chrome中运行而没有成功。
//$(document).on("change", "#postSeverity", function () {
// getRiskAcceptor();
//});
//$(document).on("change", "#postProbability", function () {
// getRiskAcceptor();
//});
//$('#postRac').on('change', function () {
// getRiskAcceptor();
//});
//$("#postSeverity").change(function () {
// alert("entering #");
// getRiskAcceptor();
//});
//$('#postProbability').change(function () {
// getRiskAcceptor();
//});
答案 0 :(得分:1)
当您设置该输入的值时,请务必明确触发该事件的change
事件
这应该有效
$(function(){
$('#postRacSeverity').change(function () {
var myValue = new Date().getSeconds();
$('#postRac').val(myValue ).trigger('change');
});
$('#postRac').on('change', function () {
console.log('value changed');
getRiskAcceptors();
});
});