0

私は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)

何か案が ?

4

2 に答える 2