简体   繁体   English

调用单引号的函数

[英]call a function with single quotes

I have to call the following javascript function 我必须调用以下javascript函数

function changeExampleField(firstValue, changeId, field, wordToChange)
{
 var exampleTxtElem = document.getElementById(changeId);
 var newTxt = field.value;
 exampleTxtElem.innerHTML = firstValue.replace(wordToChange, newTxt);
}

The problem at this is, I get the value of "firstValue" from the database, it is a String and it can contain single quotes. 这里的问题是,我从数据库中获取了“ firstValue”的值,它是一个字符串,并且可以包含单引号。 For example: 例如:

I get a value from the database which operates 我从运行的数据库中获取了一个值

<input class="" type="text" name="text_label.test_virus_connection" value="test" size="50" maxlength="50" id="a_text_label.test_virus_connection"   onkeyup="changeExampleField('Verbindung testen', 'example_label.test_virus_connection', this, 'test')"  onFocus="dispHelp('')">

But i can get values from the database which dont operates 但是我可以从无法运行的数据库中获取值

<input class="" type="text" name="text_pass_sprachtest.label.execute.successfull" value="test" size="50" maxlength="50" id="a_text_pass_sprachtest.label.execute.successfull"   onkeyup="changeExampleField('Bewerbung(en) erfolgreich auf 'Sprachtest(s) bestanden' gesetzt!', 'example_pass_sprachtest.label.execute.successfull', this, 'test')"  onFocus="dispHelp('')">

My question is: is there a different way to call the function (for example with properties or so)? 我的问题是:是否有其他方法来调用函数(例如,具有属性等)? Or a different way to solve this problem? 还是解决这个问题的另一种方法?

You should do either of this 你应该做这两个

replace outer single quotes with double quote 用双引号替换外部单引号

"Bewerbung(en) erfolgreich auf 'Sprachtest(s) bestanden' gesetzt!" “ Bewerbung(en)erfolgreich auf'sprachtest bestanden'gesetzt!”

or escape the single quotes in middle 或转义中间的单引号

'Bewerbung(en) erfolgreich auf \\'Sprachtest(s) bestanden\\' gesetzt!' 'Bewerbung(en)erfolgreich auf \\'Sprachtest bestanden \\'gesetzt!”

if you do not do ths either way then its not considered as string 如果您不这样做,则不将其视为字符串

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

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