Uncaught TypeError:无法读取null的属性'值'..(在空白行上)
问题描述:
我正在重写一个脚本,很多都是从我的原始脚本(根本没有编码问题)剪切和粘贴。Uncaught TypeError:无法读取null的属性'值'..(在空白行上)
<script type="text/javascript">
function Svdelivery() {
var dataString = "Booking_ID=" + document.getElementById('Booking_ID').value + "&Client_ID=167&DeliveryName=" + document.getElementById('DeliveryName').value + "&DeliveryNumber=" + document.getElementById('DeliveryNumber').value + "&DeliveryAddress=" + document.getElementById('DelAddress').value + "&Instructions=" + Instructions;
alert(dataString);
}
</script>
不管我做什么,如果我在那里有一个变种,它总是抛出此错误
Uncaught TypeError: Cannot read property 'value' of null
at Svdelivery (index.php?option=com_chronoforms5&chronoform=Booking&event=Delivery:98)
at HTMLInputElement.onclick (index.php?option=com_chronoforms5&chronoform=Booking&event=Delivery:564)
Svdelivery @ index.php?option=com_chronoforms5&chronoform=Booking&event=Delivery:98
onclick @ index.php?option=com_chronoforms5&chronoform=Booking&event=Delivery:564
指向行function Svdelivery() {
或下方的一个空白。我已将代码剥离,以解决问题,但仍遇到同样的问题。我也改变了功能名称,但仍然,没有...任何想法?
答
请确保在加载元素之后调用Svdelivery()
并且您在函数中加载的所有值都已加载。
看起来像编号为Booking_ID
,DeliveryName
或DeliveryNumber
的值在您致电Svdelivery()
函数时未加载。
您是否具有上述指定ID的所有元素? – Satpal
你在加载元素后调用Svdelivery()函数吗? – nnnnnn
不,但我会认为它会返回“NULL”。但我会尝试 – Ben