请看看这个小提琴.
我一直在处理附加文本的"添加全部"按钮div#area.谁能告诉我如何使用if条件来防止重复文本添加到该区域?在小提琴示例中,我不希望将"A","B"两次附加到该区域.
HTML:
<div class="addarea">
<div class="add">A</div>
<div class="add">B</div>
<div class="add">C</div>
<div class="add">D</div>
<button class="addall">Add All</button>
</div>
<div class="addarea">
<div class="add">A</div>
<div class="add">B</div>
<div class="add">F</div>
<div class="add">G</div>
<button class="addall">Add All</button>
</div>
<button id="remove">Remove</button>
<div id="area"></div>
Run Code Online (Sandbox Code Playgroud)
代码失败:
$('.addall').click(function(){
var add = $(this).closest('.addarea').find('.add');
add.each(function(){
var copy = $(this).clone(),
content = $(this).text();
if($('#area').find('.add').text() == content){
return false;
}
else
{
$('#area').append(copy);
}
});
});
$('#remove').click(function(){
$('#area').find('div').remove();
});
Run Code Online (Sandbox Code Playgroud) 我试图用来ts-jest运行tsx测试文件form.spec.tsx。
该form.spec.tsx进口React Quill编辑器和一些插件。
我如何绕过SyntaxError: Unexpected identifier来自导入的名为quill-mention的插件的错误Quill?该模块涉及form.spec.tsx。
我已经["<rootDir>/node_modules/"]在笑话配置中添加到transformIgnorePatterns字段,但是/node_modules/quill-mention/src/quill.mention.js中仍然存在此问题
? Test suite failed to run
/home/web/node_modules/quill-mention/src/quill.mention.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Quill from 'quill';
^^^^^
SyntaxError: Unexpected identifier
1 | import React from "react"
> 2 | import "quill-mention";
| ^
Run Code Online (Sandbox Code Playgroud)
form.spec.tsx:
import {render, RenderResult, waitForElement} from "react-testing-library";
import ReactQuill, {Quill} from 'react-quill';
import "quill-mention";
const renderResult = render(
<ReactQuill
modules={
{
mention: {
allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/, …Run Code Online (Sandbox Code Playgroud) 我正在使用此站点/脚本中的jQuery链式选择下拉框.我把它放在侧边栏中,它在主页上工作正常,但它不适用于帖子页面,调试器指出了这个错误.
Uncaught TypeError: Object function ()
{for(var a=[];this.length;)a.push(this.splice(Math.random()*this.length,1));
for(;a.length;)this.push(a.pop());return this} has no method 'replace'
Run Code Online (Sandbox Code Playgroud)
它说有一个错误 escapeQuotes : function(str) {return str.replace(/([""\\])/g, "\\$1");
脚本的开头:
(function($) {
$.dynamicDropdown = {
/**
* Escape quotation marks and slashes
* @param {String} String to format
* @return {String}
*/
escapeQuotes : function(str) {
return str.replace(/([""\\])/g, "\\$1");
},
Run Code Online (Sandbox Code Playgroud)
这是我如何调用该函数.我正在使用json文件将选项文本和值拉入选定的框:
$(document).ready(function(){
$.getJSON('suggest.json', function(data){
var $select = $('#mySelectID');
$.each(data, function (index, o) {
var $option = $("<option/>").attr("value", o.Box1ID + ":" + o.Box3).text(o.Box1 + "|" …Run Code Online (Sandbox Code Playgroud) 我不明白为什么当可扩展列表视图在带有分隔符设置的对话框片段中膨胀时,我的应用程序崩溃了.它只发生在Android 6.0中.Android 4.2没问题.
expandablelistview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/filter_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/scroll_layout"
android:background="#fff"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ExpandableListView
android:id="@+id/expandable_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/primaryLight"
android:dividerHeight="5dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
对话框片段的一部分:
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
if(savedInstanceState == null) {
final Context context = getActivity();
Bundle bundle = getArguments();
Map<String, List<FilterItem>> listCollection = (Map<String, List<FilterItem>>) bundle.getSerializable(DATA);
List<String> groupList = (List<String>) bundle.getSerializable(GROUP);
ExpandableListView expListView = (ExpandableListView) view.findViewById(R.id.expandable_list);
final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(context, groupList, listCollection);
expListView.setAdapter(expListAdapter);
expListView.expandGroup(0);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为崩溃是由xml中的分隔符设置引起的.部分错误表示失败setBounds(android.graphics.Rect),所以我猜它与分隔符有关:
android:divider="@color/primaryLight"
android:dividerHeight="5dp" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使docker容器与mariadb和node.js图像一起使用。容器将使用中的现有数据库/home/mysql。但是,当启动容器时,我在node.js中收到此“连接失败”错误:
Error: ER_HOST_NOT_PRIVILEGED:
Host '172.18.0.5' is not allowed to connect to this MariaDB server
Run Code Online (Sandbox Code Playgroud)
这是我的docker-compose.yml:
version: '3'
services:
mariadb:
image: mariadb
restart: always
volumes:
- /home/mysql:/var/lib/mysql
user: "mysql"
ports:
- "3306:3306"
watch:
build: .
restart: always
links:
- mariadb:mysql
environment:
- DOCKER_IP=172.18.0.2
depends_on: ['mariadb']
ports:
- "3000:3000"
Run Code Online (Sandbox Code Playgroud)
阅读此线程后,我发现mysql实际上正在运行,但是无法让其他服务连接:
这些是我检查过的一些步骤。如您所见,我可以登录到mysql实例:
$ docker exec -it 552aae9ea09c bash
mysql@552aae9ea09c:/$ mysql -u root -p
Enter password: *******
MariaDB [(none)]> SELECT host, user FROM mysql.user;
+-------------+------------------+
| host | user | …Run Code Online (Sandbox Code Playgroud) 请看看这个小提琴.
我无法将输入框附加到div元素.
有没有办法让整个短语(例如"选项1")进入值属性的双引号?
Firebug显示空格后面的单词(本例中为"1")超出了引号,如下所示:
<input type="radio" value="Option" 3>
Run Code Online (Sandbox Code Playgroud)
但我希望它是:
<input type="radio" value="Option 3">
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="post_text"></div>
<select multiple>
<option value="A">Option 1</option>
<option value="B">Option 2</option>
<option value="C">Option 3</option>
<option value="D">Option 4</option>
<option value="E">Option 5</option>
<option value="F">Option 6</option>
</select>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var post_text = $('#post_text');
$("select").multiselect({
selectedText: "# of # selected",
click: function (event, ui) {
if (ui.checked) {
var span = '<input type="radio" value='+ ui.text +'><div id="' + ui.value + '">'+ ui.text +'</div>'
post_text.append(span);
} else {
post_text.find('#'+ui.value).remove();
}
} …Run Code Online (Sandbox Code Playgroud)