简体   繁体   English

发布带有控制字符的表单

[英]Posting a form with control characters

I'm puzzled by finding out that newer version of Chrome, Opera and Safari don't allow control characters in text inside INPUT elements. 我被发现Chrome,Opera和Safari的较新版本不允许INPUT元素内的文本中的控制字符感到困惑。 In fact, characters like \\1 , \\x02 , \\b etc. are simply interpreted as string terminators. 实际上,像\\1\\x02\\b等字符只是被解释为字符串终止符。

var input = document.createElement('INPUT');
input.value = 'Hello\x02 World!';
alert('input.value is "' + input.value + '" (' + input.value.length + ' chars)');

The code above only outputs 5 characters on Chrome, Opera and Safari. 上面的代码在Chrome,Opera和Safari上仅输出5个字符。

Firefox and IE do not show this behavior/bug/security feature or whatever. Firefox和IE不会显示此行为/错误/安全功能或任何其他功能。 Now my question is how would you post a form containing those special characters in plain Javascript, in a way that works in all browsers? 现在我的问题是,您将如何以一种适用于所有浏览器的方式发布一个包含这些特殊字符的纯Java表单?

JsFiddle: http://jsfiddle.net/Nkx4n/ JsFiddle: http : //jsfiddle.net/Nkx4n/

I'm in chrome and, like you, if i try to asign to the input a string with \\ in it, it stop, but there is no problem if the user enter it in the input directly, like you can see in this fiddle 我在chrome中,和您一样,如果我尝试在输入中指定一个带\\的字符串,它会停止,但是如果用户直接在输入中输入它就没有问题,就像您在此提琴中看到的那样

    myP.innerHTML = "Length is: " + myInput.value.length + " chars" + "; text is: " + myInput.value;

I don't know if you need to set the value in code but if you don't there shouldn't be any problem because the user can still enter it and it's read. 我不知道您是否需要在代码中设置该值,但是如果您不需要,则不会有任何问题,因为用户仍然可以输入它并且可以读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM