使用包含双引号的字符串填充输入字段 [英] Populate an input field with a string that contains a double quote

查看:54
本文介绍了使用包含双引号的字符串填充输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器中获取了一个包含双引号的值.我需要使用该值填充输入标签.

I'm getting a value back from the server that contains a double quote in it. I need to populate an input tag with the value.

我尝试使用转义(myVariable),但是将空格转换为%20,依此类推.我想我可以写一个if/then,如果字段中有双引号,然后使用value ='',但是如果字段中有双引号和单引号,那该怎么办?

I've tried using escape(myVariable), but that converts the spaces to %20, etc. I suppose I could write an if/then that says if there's a double quote in the field, then use value='', but then what do I do if they have both double and single quotes in the field?

推荐答案

input.value = val.replace(/"/g, '"');

这篇关于使用包含双引号的字符串填充输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆