我正在encodedURIComponentValue()
为 Javascript 字符串编写此方法:
这个想法是让我打电话:"some string".encodedURIComponentValue()
代码如下:
if (typeof String.prototype.encodedURIComponentValue != 'function') {
String.prototype.encodedURIComponentValue = function (str) {
if (str && str.length > 0)
return encodeURIComponent(str);
else
return "";
};
}
但在某些情况下它不起作用:
var encodedVal = $("body").find("option:selected").first().text().encodedURIComponentValue() // text() = "Option1"
console.log(encodedVal); // I only see "" (empty)
任何想法 ?