dongpaipu8394 2011-03-25 20:28
浏览 74

如何将“”“传递给在HTML标签内进行的Javascript函数调用?

I have a Javascript function (named insert_formatText) which inserts text into a specified textarea. This function takes 4 parameters: - opentag (the open tag) - closetag (the close tag) - formid (id-attribute value of the form) - elementid (id-attribute value of the textarea)

My function works very well except for when you set opentag as """ and closetag as """. In that case, it simply breaks.

<a href="javascript:;" onclick="insert_formatText('"""', '"""', 'foo', 'bar');">INSERT TRIPLE-QUOTES</a>

Extra Detail

I actually use PHP to loop through an array containing the opentag and closetag values as a key => value pair. In the loop, I pass those values to a function:

function editorButton($pre, $suf, $fid, $eid, $label){
    $str = <<<EOT
            <a href="javascript:;" onclick="insert_formatText('$pre', '$suf', '$fid', '$eid');">$label</a>
EOT;
    return $str;
}

So my question: is there anyway to get this to work for double-quotes without much changing? Or will I have to find a different method to generate these buttons?

  • 写回答

4条回答 默认 最新

  • drbhjey445647 2011-03-25 20:30
    关注

    You can escape the quotes using a backslash in this manner:

    <a href="javascript:;" onclick="insert_formatText('\"\"\"', '\"\"\"', 'foo', 'bar');">INSERT TRIPLE-QUOTES</a>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程