简体   繁体   English

Javascript onmouseover尝试向文本添加“

[英]Javascript onmouseover trying to add " to text

So I am very new to javascript and web development in general. 因此,对于一般的javascript和Web开发我还是很陌生的。 I am trying to make it so that when you hover over text a small text box pops up with a paragraph in it. 我试图这样做,以便当您将鼠标悬停在文本上时,会弹出一个小文本框,其中带有一个段落。 The problem is that I need to add " in the text however when I do that the script doesn't work as it recognizes " as part of the code. 问题是我需要在文本中添加“”,但是当我这样做时,脚本将无法识别,因为该脚本无法识别代码。

I am using nhpup popups to do that nhpopup site 我正在使用nhpup弹出窗口来执行该nhpopup网站

This is what I am trying to add " to 这就是我要添加的“

 /* -------------------------------------------------------------------------- Code for link-hover text boxes By Nicolas Höning Usage: <a onmouseover="nhpup.popup('popup text' [, {'class': 'myclass', 'width': 300}])">a link</a> The configuration dict with CSS class and width is optional - default is class .pup and width of 200px. You can style the popup box via CSS, targeting its ID #pup. You can escape " in the popup text with &quot;. Tutorial and support at http://nicolashoening.de?twocents&nr=8 -------------------------------------------------------------------------- The MIT License (MIT) Copyright (c) 2014 Nicolas Höning Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ nhpup = { pup: null, // This is the popup box, represented by a div identifier: "pup", // Name of ID and class of the popup box minMargin: 15, // Set how much minimal space there should be (in pixels) // between the popup and everything else (borders, mouse) default_width: 500, // Will be set to width from css in document.ready move: false, // Move it around with the mouse? we are only ready for that when the mouse event is set up. // Besides, having this turned off initially is resource-friendly. /* Write message, show popup w/ custom width if necessary, make sure it disappears on mouseout */ popup: function(p_msg, p_config) { // do track mouse moves and update position this.move = true; // restore defaults this.pup.removeClass() .addClass(this.identifier) .width(this.default_width); // custom configuration if (typeof p_config != 'undefined') { if ('class' in p_config) { this.pup.addClass(p_config['class']); } if ('width' in p_config) { this.pup.width(p_config['width']); } } // Write content and display this.pup.html(p_msg).show(); // Make sure popup goes away on mouse out and we stop the constant // positioning on mouse moves. // The event obj needs to be gotten from the virtual // caller, since we use onmouseover='nhpup.popup(p_msg)' var t = this.getTarget(arguments.callee.caller.arguments[0]); $jq(t).unbind('mouseout').bind('mouseout', function(e){ nhpup.pup.hide(); nhpup.move = false; } ); }, // set the target element position setElementPos: function(x, y) { // Call nudge to avoid edge overflow. Important tweak: x+10, because if // the popup is where the mouse is, the hoverOver/hoverOut events flicker var x_y = this.nudge(x + 10, y); // remember: the popup is still hidden this.pup.css('top', x_y[1] + 'px') .css('left', x_y[0] + 'px'); }, /* Avoid edge overflow */ nudge: function(x,y) { var win = $jq(window); // When the mouse is too far on the right, put window to the left var xtreme = $jq(document).scrollLeft() + win.width() - this.pup.width() - this.minMargin; if(x > xtreme) { x -= this.pup.width() + 2 * this.minMargin; } x = this.max(x, 0); // When the mouse is too far down, move window up if((y + this.pup.height()) > (win.height() + $jq(document).scrollTop())) { y -= this.pup.height() + this.minMargin; } return [ x, y ]; }, /* custom max */ max: function(a,b) { if (a>b) return a; else return b; }, /* Get the target (element) of an event. Inspired by quirksmode */ getTarget: function(e) { var targ; if (!e) var e = window.event; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) // defeat Safari bug targ = targ.parentNode; return targ; }, onTouchDevice: function() { var deviceAgent = navigator.userAgent.toLowerCase(); return deviceAgent.match(/(iphone|ipod|ipad|android|blackberry|iemobile|opera m(ob|in)i|vodafone)/) !== null; }, initialized: false, initialize : function(){ if (this.initialized) return; window.$jq = jQuery; // this is safe in WP installations with noConflict mode (which is default) /* Prepare popup and define the mouseover callback */ jQuery(document).ready(function () { // create default popup on the page $jq('body').append('<div id="' + nhpup.identifier + '" class="' + nhpup.identifier + '" style="position:absolute; display:none; z-index:200;"></div>'); nhpup.pup = $jq('#' + nhpup.identifier); // set dynamic coords when the mouse moves $jq(document).mousemove(function (e) { if (!nhpup.onTouchDevice()) { // turn off constant repositioning for touch devices (no use for this anyway) if (nhpup.move) { nhpup.setElementPos(e.pageX, e.pageY); } } }); }); this.initialized = true; } }; if ('jQuery' in window) nhpup.initialize(); 
 <a onmouseover="nhpup.popup('Action Relating to or affecting the fundamental nature of something; far-reaching or thorough. This is what we offer at Rad Surfing Bali. We provide the most radical way of learning how to surf.');" href='#'>Radical.</a> 

Please help me add a " to the text in the html script. 请帮助我在HTML脚本的文本中添加一个“”。

Regards, Kraz 问候,克拉兹

You should escape '' chars with \\ . 您应该使用\\逃避''字符”。
Like this 像这样

<a onmouseover="nhpup.popup('Action Relating to or affecting the fundamental nature of something; far-reaching or thorough. This is what we offer at \'Rad Surfing Bali\'. We provide the most radical way of learning how to surf.');" href='#'>Radical.</a>

Here is working example https://jsfiddle.net/xkj66svc/ 这是工作示例https://jsfiddle.net/xkj66svc/

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

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