![](/img/trans.png)
[英]leaflet image - Uncaught TypeError: Cannot read property 'match' of undefined
[英]Uncaught TypeError: Cannot read property 'match' of undefined
使用這段jQuery,我檢查一些字段是否匹配或不為空,但我收到此錯誤。
未捕獲的TypeError:無法讀取未定義的屬性“匹配”
誰能告訴我這里做錯了什么?
if ( width.match( /^\d+$/ ) && height.match( /^\d+$/ ) && type.length > 0 && color.length > 0 ) {
這是完整的代碼:
if( $( "#config" ) ) {
$( 'input, select' ).on( 'change', function(){
var width = $( "#config-steps #width" ).val();
var height = $( "#config-steps #height" ).val();
var type = $( "#config-steps #type" ).val();
var color = $( "#config-steps #selected-color" ).val();
if ( width.match( /^\d+$/ ) && height.match( /^\d+$/ ) && type.length > 0 && color.length > 0 ) {
$( "#checkout-message" ).show();
// Change visible price
$( "#change-price" ).html( calculate_price().toFixed( 2 ) );
} else {
return false;
}
});
}
if( $( "#config" ) ) {
jQuery總是如此,因為jQuery返回一個對象,對象是真實的。 檢查應檢查將返回數字的長度,零為假。
if ($("#config").length) {
現在當jQuery找不到元素時,val()將返回undefined,因此它找不到元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.