如何使用 php 对输入元素值进行 urlencode 后将其传递给 javascript
我有一个输入文本字段。
按 Enter 键后,我正在执行以下操作
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null) {
link = "message.php?nick="+nickName+"&msg="+document.getElementById('msg').value;
httpObject.open("GET", link , true);
httpObject.onreadystatechange = setOutput;
httpObject.send(null);
}
}
我想要的是对值进行“urlencode”。
我该怎么做?
I've an input text field.
On press enter, i'm performing the following action
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null) {
link = "message.php?nick="+nickName+"&msg="+document.getElementById('msg').value;
httpObject.open("GET", link , true);
httpObject.onreadystatechange = setOutput;
httpObject.send(null);
}
}
What I want is to "urlencode" the value.
How should I do that??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 JavaScript 函数encodeURIComponent
link = "message.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
Use the JavaScript function encodeURIComponent
link = "message.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
只需用“escape”包装该值,如下所示:
Just wrap the value with "escape" as in: