Uncaught TypeError: Cannot read properties of undefined (reading 'target') & (reading 'value')
Uncaught TypeError: Cannot read properties of undefined (reading 'target') & (reading 'value')
JQuery版本从2.14升级到3.5.0后,出现如下错误,但我没有完全理解是什么问题,有radio = event.target Cannot Read Properties of Undefined (Reading 'target') 定义中收到的错误
谁能帮我解决一下?*
var testMethod = {
testSubMethod: function (event) {
var radio = event.target;
var isMultiInput = $('#MultipleInputYes').is(':checked');
if (!isMultiInput || radio.value == undefined) {
$('.divMultiInput').addClass("dp-none");
if (radio.value == 'false') {
$('#divInputValueType').prop('disabled', false);
$('#divInputValueType').attr('style', '');
}
}
},
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
<div class="radio radio-success">
<input type="radio" id="MultipleInputYes" value="true" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputYes"> Yes</label>
</div>
<div class="radio radio-success">
<input type="radio" id="MultipleInputNo" value="false" checked="checked" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputNo">No</label>
</div>
testMethod.testSubMethod(this)
this - 在你的案例中引用了 html 对象。
所以可能会改变
testSubMethod: function (event) {
var radio = event.target;
这样的事情可能会解决你的问题
testSubMethod: function (el) {
var radio = el;
我相信 event
必须在
中未定义
var radio = event.target;
因此,当您尝试访问 event.target
时,您正在访问 undefined
的 target
属性,这是 javascript 中的错误
尝试检查事件是否首先定义
var radio = event ? event.target : undefined
JQuery版本从2.14升级到3.5.0后,出现如下错误,但我没有完全理解是什么问题,有radio = event.target Cannot Read Properties of Undefined (Reading 'target') 定义中收到的错误 谁能帮我解决一下?*
var testMethod = {
testSubMethod: function (event) {
var radio = event.target;
var isMultiInput = $('#MultipleInputYes').is(':checked');
if (!isMultiInput || radio.value == undefined) {
$('.divMultiInput').addClass("dp-none");
if (radio.value == 'false') {
$('#divInputValueType').prop('disabled', false);
$('#divInputValueType').attr('style', '');
}
}
},
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
<div class="radio radio-success">
<input type="radio" id="MultipleInputYes" value="true" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputYes"> Yes</label>
</div>
<div class="radio radio-success">
<input type="radio" id="MultipleInputNo" value="false" checked="checked" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputNo">No</label>
</div>
testMethod.testSubMethod(this)
this - 在你的案例中引用了 html 对象。
所以可能会改变
testSubMethod: function (event) {
var radio = event.target;
这样的事情可能会解决你的问题
testSubMethod: function (el) {
var radio = el;
我相信 event
必须在
var radio = event.target;
因此,当您尝试访问 event.target
时,您正在访问 undefined
的 target
属性,这是 javascript 中的错误
尝试检查事件是否首先定义
var radio = event ? event.target : undefined