以下はblur、ASP MVC 3 ビューのテキスト ボックスにイベントを配置するために使用しているコードです。が空の場合、コードは正常に機能します#MailingStateが、が空かどうかはわかりません#channelName。
たとえば、#channelName空であるがそうでない場合、 Ajax 呼び出し#MailingStateに値を配置すると、毎回起動されます。#MailingZipgetDrmTerritory
ここにjQueryがあります
$('#MailingZip').blur(function () {
if ($('#AlignmentM').is(':checked')) {
if ($('#MailingState').val() != "" && $('#channelName').html() != "") {
getDrmTerritory($('#MailingZip').val(), $('#MailingState').val(), $('#channelName').html());
}
}
});
#channelNameチェックしているセグメントの HTML は次のとおりです。
<div id="channelName" class="M-display-field">
@*this will be updated via ajax from Market Segment *@
@Html.DisplayFor(model => model.Channel, new { style = "margin-left: 300px;" } )
</div>
コメントに記載されているセクションは、次のような別の jQuery メソッドを介して更新されます
function ChangeChannel() {
//this function called if Market Segment changes, to update the channel
var pendistcode = document.getElementById('Pendist');
if (pendistcode == null) alert('Error: Cannot find Market Segment control');
//alert('!pendistcode value is ' + pendistcode.value);
$.ajax({
type: 'POST',
url: '/AgentTransmission/GetChannel/',
data: { pendist: pendistcode.value },
success: function (data) {
// alert("success: " + data);
$('#channelName').html(data);
$('#Channel').val(data);
},
error: function (data) {
alert("failure to obtain Channel name");
}
});
CheckTerritory('channel');
} //end ChangeChannel
その jQuery メソッド ( ChangeChannel) は、channelNamedivにテキストを追加します。値を指定してレンダリングすると、次のようになります。

Life Salesその画像から を調べたときに得られる HTML は次のとおりです。
