如何从样式百分比防止“URIError:格式错误的URI序列”

时间:2015-06-22 07:23:46

标签: javascript

我有这个代码:

  

的javascript:如果(的document.getElementById( 'linky'))%20 {%20%20%20%20document.getElementById( 'linky')值= splitdo;}否则%20 {利亚=使用document.createElement( 'textarea的'); tarea.style.position = '固定'; tarea.style.top = '5%'; tarea.style.left = '5%'; tarea.style.width = '400像素'; tarea.style .height = '100像素'; tarea.id = 'linky'; tarea.value = splitdo; document.body.appendChild(利亚);};无效(0);

我想使用decodeURIComponent函数对其进行解码。现在的问题是它给了我错误URIError: malformed URI sequence 我知道在这个网站上已经多次询问过这个问题,但我的情况有点不同 经过一些工作后,我发现问题出现在它有数字百分比的行上(即tarea.style.top='5%';tarea.style.left='5%';
如果删除百分比,则该函数不会抛出任何错误。我知道这是因为百分之后没有任何东西,但我不知道如何防止这个错误。我希望百分比在那里,我不想使用像素。我该怎么做才能保留5%,但要防止出现此错误? 可以预防吗?

1 个答案:

答案 0 :(得分:2)

decodeURIComponent不起作用。我发现我应该使用unescapehttps://github.com/w8tcha/CKEditor-TextSelection-Plugin/issues/18