值得一记。
可能获取到的对象为undefined。【我的错误原因,$("#XxxID")忘记给 DOM对象 加id属性。导致拿到的对象是undefined】
==========
参考:https://stackoverflow.com/questions/32733423/uncaught-typeerror-cannot-read-property-trim-of-undefined-in-jquery
核心内容:【英文答案还是要看看的。 哈哈】
You're getting error
Uncaught TypeError: Cannot read property 'trim' of undefined in Jquery
that means, the variable vname is undefined. To prevent this error from occurring, you can use the ternary operator to set the default value of the string to empty string when it is undefined.
var vname = $("#EarningsTypes").val() == undefined ? '' : $("#EarningsTypes").val().trim();
vname = vname.replace(/ /g, '%20');
You can also use || to set the default value
var vname = $("#EarningsTypes").val() || '';