我正在制作一个脚本,用户在屏幕上选择(当他们在浏览器中物理突出显示文本时)并且应该操纵该文本.
这就是我想要做的.
获取所选文本,在原始字符串中搜索所选文本,然后使用特定HTML标记包装原始字符串中找到的文本(<b>, <span>, <a>)
我正在使用jQuery.textselect插件.
我找不到的部分是如何在找到用户选择后操纵原始文本.
示例:如果屏幕上显示此文本:"HELLO WORLD"
原始文本是HELLO WORLD,用户选择HELLO,然后脚本在原始文本中搜索用户选择,并将HELLO包含<b>标签,然后输出新的原始文本......有意义吗?
对不起,感谢困惑,感谢您的帮助!
有没有一种方法可以在jQuery中找到jQuery中的文本字符串,而不是用其他东西替换它,但是用一个元素包装该文本,这样当脚本完成时,它会用文本字符串包裹原始文本.
例:
原文
"Hello world to all people"
Run Code Online (Sandbox Code Playgroud)
搜索字符串
"world to"
Run Code Online (Sandbox Code Playgroud)
用...来代替 <i></i>
最终输出
"Hello <i>World to</i> all people"
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
一种工作代码:
function highlightChild(child) {
$(childElements[child]).text("");
console.log(child);
$('.child_element_' + child).bind('textselect', function(e){
var selection = e.text;
var str = $("#construct_version").text();
var wrap = jQuery(childElements[child]).text(selection);
var re = new RegExp("" + selection + "", "g");
console.log(str.replace(selection, function(match, key, val){
console.log(match);
console.log(key);
console.log(val);
jQuery(childElements[child]).text(val)
}));
});
}
Run Code Online (Sandbox Code Playgroud)
上面的代码执行替换,但它实际上替换它显示为undefined.
因此,如果原始字符串是所有人的Hello world并且我想要将world替换为with <b>world to</b>,则它在console.log中显示为Hello undefined all
我已经尝试了关于在MAMP环境下安装PHP OAuth扩展的所有教程,但由于某些原因无法加载它.
我正在使用MAMP 1.9和PHP 5.3.2
我关注的最新教程是:http://lifeofadev.com/2011/03/09/mac-os-x-installing-oauth-so-into-xampp-mamp/
有没有其他人有这方面的工作经验?
谢谢!丹尼斯
我有一个脚本,它在我的搜索输入框中的 keyup 事件上执行 ajax 请求。我在 Firefox 中注意到(我正在查看控制台),发送的每个请求都完成了。所以有大量的ajax请求发生。
无论如何要在keyup事件中杀死正在进行的ajax请求?
jQuery:
jQuery(function() {
var request;
request = function(url, keyword) {
return $.post('/backpack/' + url + '/search?keyword=' + keyword, function(data) {
var el;
el = "#result_" + url;
return $(el).html(data);
});
};
$("#search_text").bind("keyup", function() {
var query, url, _i, _len, _ref;
query = $(this).val();
if (query.length > 2) {
_ref = ['tracks', 'albums', 'artists'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
url = _ref[_i];
request(url, query);
}
return …Run Code Online (Sandbox Code Playgroud) 出于某些原因,在我的本地环境中,每次更改模型时,我都必须重新启动控制台而不是重新加载它.我在我的development.rb中将cache_classes设置为false ...出现这种情况的原因是什么?
这是我的代码:
<p><%= image_tag "/assets/logos/#{@company_name.downcase}_logo.jpg" %></p>
发送电子邮件后,我在电子邮件客户端中查看电子邮件时,图像未显示.它看起来像一个破碎的图像
其他人遇到这个问题?
这是我的 development.rb
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports …Run Code Online (Sandbox Code Playgroud) 我正在开发一个包含API使用grapegem 的应用程序.
这是我的Root班级:
module API
class Root < Grape::API
rescue_from :all do |e|
Rack::Response.new(
[ "Error: #{e.message}" ],
500,
{ "Content-type" => "text/error" }
).finish
end
prefix "api"
version 'v1', using: :path
format :json
error_format :json
mount ::API::ServiceRequests
end
end
Run Code Online (Sandbox Code Playgroud)
以下是我如何在路线中安装它:
mount API::Root => '/'
我收到的错误是:
routes.rb:45:in阻止':未初始化的常量API(NameError)`
文件结构相似app/api/root.rb,我在我application.rb的文件中加载了这些代码:
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
Run Code Online (Sandbox Code Playgroud) 我正在开发一个节点应用程序,它本质上是一个简单的AWS SQS轮询器,应该坐下来收听不同队列中的新项目.
这是我的module.export:
module.exports = {
readMessage: function(qParams, qType, tableName) {
logger.debug(qType);
SQS.receiveMessage(qParams, handleSqsResponse);
function handleSqsResponse (err, data) {
if(err) logger.error("handleSqsResponse error:" + err);
if (data && data.Messages) {
data.Messages.forEach(processMessage)
readMessage(); // continue reading until draining the queue (or UPTIME reached)
}
else{
logger.debug("no data in sqs.");
// process.exit();
}
}
// 'processing' is mainly writing to logs using winston. Could add here any transformations and transmission to remote systems
function processMessage(sqsMessage){
// Parse sqs messag
var msgObj …Run Code Online (Sandbox Code Playgroud) 我在新的 Rails 6 应用程序中安装了 Stimulus.js。
在我的文件中packs/application.js,我有以下内容:
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag …Run Code Online (Sandbox Code Playgroud) 我有以下HTML标记:
<div id="step1" class="step">
<h1>Enter code</h1>
<p><input type="text" value="<%= @groupCode %>" name="group_code" class="span3" />
<a class="btn btn-primary btn-medium">
Next »
</a>
</p>
</div>
<div id="step2" class="step" style="display: none">
<p>Hello World</p>
</div>
Run Code Online (Sandbox Code Playgroud)
单击链接(.btn)后,我需要显示下一个父div(#step2).我将其设计为注册过程,因此将有多个父div(所有以step {:id}命名)
任何帮助深表感谢!