我有一个标签,其中预填充了值 Coeur D'alene。标签定义为
<label for="otherSpokenLanguage" class="hide"><spring:message code="label.entity.otherSpokenLangugesInput"/></label>
现在的问题是当我尝试执行 $("#otherSpokenLanguage").val(); 时
我只得到Coeur D
有什么方法可以获取 Coeur D'alene 标签内的全部值
最佳答案
我的猜测(没有看到输出 html)是 value
属性应用单引号 '
,因此引号中文本使属性结束。
类似
<input id='otherSpokenLanguage' value='Coeur D'alene' />
(看到问题了吗?)
<小时/>您必须将包装引号设置为双 "
(如果该值现在包含 "
,您将遇到相同的问题)
<input id="otherSpokenLanguage" value="Coeur D'alene" />
或对值进行 html 编码,使其中的 '
变为 '
<input id='otherSpokenLanguage' value='Coeur D'alene' />
关于javascript - .val() 函数正在 trim 特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23912792/