简体   繁体   English

变量内的引号

[英]quotation mark inside variable

i'm trying to do very simple thing: 我正在尝试做非常简单的事情:
store quotation mark ( " or ' ) inside variable on javascript event 将引号( "' )存储在javascript事件的变量内
(for example: onerror (img element)) (例如:onerror(img元素))
my code: 我的代码:

<img onerror="var m ='"';  document.write(m);">

or: 要么:

<img onerror='var m = "'";  document.write(m);'>


I do not need to explain why this code does not work(the attribute)... 我不需要解释为什么此代码不起作用(属性)...
(onerror= " var m =' " '; document.write(m); " >) (onerror = " var m =' " '; document.write(m); " >)

note : i can't use charAt or fromcharcode i'm trying to do it without any function ( alternatives ). 注意 :我不能使用charAtfromcharcode我正在尝试没有任何功能( 替代方法 )。

只需使用反斜杠\\"进行转义,即... onerror="var m='\\"'; ...

Declare a function as a handler of your event and use it that way. 声明一个函数作为事件的处理程序,并以此方式使用它。

<script>
   function onImgError() {
      var m ='"';
      document.write(m);"
   }
</script>

<img onerror="onImgError()">

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

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