小编Zak*_*rki的帖子

键盘事件正在降低性能

我的例子:

$(document).on('keyup', '[contenteditable=true]', function (e) {
        
    let _this = $(this), text = _this.text();

    if (text.length === 1) {
        let span = $('<span>').text(text);
        _this.html(span);
    }

    console.log(_this.html());

});
Run Code Online (Sandbox Code Playgroud)
[contenteditable=true] {
  border: 1px solid #ccc;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div contenteditable="true"></div>
Run Code Online (Sandbox Code Playgroud)

我的问题:如果我以正常速度在div中键入一些文本(超过1个字符),则代码可以正常工作。但是,当我尝试快速键入文本时,没有将<span>标签附加到div。

我该如何解决?

html javascript jquery keyup

2
推荐指数
1
解决办法
1639
查看次数

使用jQuery隐藏某些表格单元格

我是jQuery的新手,如果我单击一行,我想隐藏所选行的某些单元格,如果再次单击则显示回来.我到处寻找但找不到任何解决方案.大部分隐藏完整的行.这是示例表:

$('.selectme').click(function() {
  $(this).has('td.hidene').hide();
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id='table1' border="1">
  <tr class='selectme'>
      <td class='donthide'>row 1, cell 1</td>
      <td class='hideme'>row 1, cell 2</td>
      <td class='hideme'>row 1, cell 3</td>
      <td class='hideme'>row 1, cell 4</td>
  </tr>
  <tr class='donthideme'>
      <td class='dontletmehide'>row 2, cell 1</td>
      <td class='dontletmehide'>row 2, cell 2</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

2
推荐指数
1
解决办法
58
查看次数

在PHP循环中使用javascript onclick

我正在尝试将一个简单的数量输入框加减1,如下图所示可能会有所不同:

在此处输入图片说明

PHP:

$query = ...
while ($row= mysqli_fetch_array($query)) 
{
     <input type="hidden" value="<?php echo $row['id']; ?>" id="id_part">
     <input type="text" value="<?php echo $row['quantity']; ?>" id="<?php echo $row['id']; ?>_count"><br>
     <input type="button" value="-" id="minus" onclick="minus()">
     <input type="button" value="+" id="plus" onclick="plus()">
}
Run Code Online (Sandbox Code Playgroud)

Javascript:

<script>
     var count = 1;
     var id = document.getElementById("id_part").value;
     var countEl = document.getElementById(id + "_count");
     function plus(){
      count++;
      countEl.value = count;
     }
     function minus(){
      if (count > 1) {
       count--;
       countEl.value = count;
      }  
     }
</script>
Run Code Online (Sandbox Code Playgroud)

没用 我只需要第一个id数量框。无法管理ID应当不同的第二个数量框。如您所见,我为每个id标记分配了不同的名称,这些名称取自数据库id。

javascript php while-loop

2
推荐指数
1
解决办法
792
查看次数

jquery-click-event的多个触发器

很抱歉这个简单的问题,但如何添加多个触发器jquery-click-event

我在这里试过那个

$("#trigger1","#trigger2").click(function() {
    //something
});
Run Code Online (Sandbox Code Playgroud)

但这不起作用.那里的语法是什么?

javascript jquery

2
推荐指数
1
解决办法
473
查看次数

如果选项值匹配显示div - jQuery

我试图显示一个div,如果选项的值匹配,无法显示,请帮忙!

注意:不能使用div的ID或类,因为html是动态生成的,它可能会被更改,因此有针对性的是选项值

这是代码:

$('select').change(function() {
  if ($('option').val() == 'Clear my checklist') {
    $('.showcontent').show();
  }
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<select name="guideContainer-rootPanel-checklist-guidedropdownlist___jqName" style="position: relative;" size="1" role="combobox" tabindex="0" aria-label="Drop-down List" id="guideContainer-rootPanel-checklist-guidedropdownlist___widget">
    <option id="emptyValue" role="option" value="Options" style="">Options</option>
    <option role="option" data-user-option="" value="Print my checklist">Print my checklist</option>
    <option role="option" data-user-option="" value="Email my checklist">Email my checklist</option>
    <option role="option" data-user-option="" value="Clear my checklist">Clear my checklist</option>
    <option role="option" data-user-option="" value="Sign out of my checklist">Sign out of my checklist</option>
</select>
<div class="showcontent" style="display:none;">Show content if value matching</div>
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

2
推荐指数
1
解决办法
935
查看次数

不使用查询启动Query Builder

所以,我可以使用User::where('username', '!=', null)->get();

但是,我的情况是我希望使用if条件从第一个开始链接查询,where('username', '!=', null)在这种情况下是不必要的.让我举一个伪示例:

我正在运行基于用户的报告,其中有多个字段.我想像这样初始化查询构建器,并使用if语句链查询.

$user = User::class();   // I know I can't use this line, however you'll get the idea.

if (isset($gender)) {
   $user = $user->where('gender', $gender);
}

if (isset($age)) {
   $user = $user->where('age', $age);
}

$users = $user->get()
Run Code Online (Sandbox Code Playgroud)

是启动查询(在第一行)的唯一方法:

$user = User::where('username', '!=', null)
Run Code Online (Sandbox Code Playgroud)

laravel eloquent laravel-5 laravel-query-builder

2
推荐指数
1
解决办法
50
查看次数

如何从Javascript中的id获取图像的url

我知道这是一个初学者的事情。所以我在一个带有 id 拇指的 div 中有这个图像。

<img id="thumb" src="https://url-to-a-image">
Run Code Online (Sandbox Code Playgroud)

这个 Javascript 它是一个放大脚本:

<script type="text/javascript">
    var myImgSrc = document.getElementById("thumb").getElementsByTagName("img") 
[0].src;
    var evt = new Event(),
    m = new Magnifier(evt);
    m.attach({
        thumb: '#thumb',
        large: 'myImgSrc',
        largeWrapper: 'preview'
    });
</script>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在尝试使用 myImgSrc 获取图像,然后我尝试在大文件中使用:'myImgSrc'。当我把一个固定的 url 放在大的时候:fixed-url-to-the-image,它工作正常。

javascript magnifier.js

2
推荐指数
1
解决办法
2514
查看次数

fSelect 清除选择

如何清除fSelect单击事件中的多选下拉列表,这是一个示例 通过单击清除按钮它应该删除所有选定的值。

(function($) {
    $(function() {
        $('.my-select-box').fSelect();
        $('#ClearSelect').click(function(){
           $("#fselectMulti option:selected").removeAttr("selected");
        })
    });
    
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://facetwp.com/wp-content/plugins/facetwp/assets/vendor/fSelect/fSelect.css" rel="stylesheet"/>
<script src="https://facetwp.com/wp-content/plugins/facetwp/assets/vendor/fSelect/fSelect.js"></script>
<select id="fselectMulti" class="my-select-box" multiple="multiple">
    <optgroup label="Northeast">
        <option selected value="me">Maine</option>
        <option selected value="ny">New York</option>
        <option value="nj">New Jersey</option>
        <option value="vt">Vermont</option>
    </optgroup>
    <optgroup label="Southwest">
        <option value="az">Arizona</option>
        <option selected value="nm">New Mexico</option>
        <option value="ca">California</option>
        <option value="nv">Nevada</option>
    </optgroup>
</select>

<button id="ClearSelect">Clear</button>
Run Code Online (Sandbox Code Playgroud)

javascript jquery multi-select fselect

2
推荐指数
1
解决办法
5373
查看次数

SQLSTATE [23000]:违反完整性约束:1052 order子句中的列“ created_at”不明确,Laravel 5.5

我只是不知道我的代码出了什么问题以及为什么它会产生此错误

SQLSTATE [23000]:完整性约束违规:1052列'created_at'为了子句是不明确的(SQL:从选择* processes内部联接bagsprocessesbag_id= bagsid其中bagstype=可回收和日期(processescreated_at)= 2018年9月18日00:00: 00按created_atdesc限制1 排序),这是我的代码

$bag = Bagcollect::join('bags', 'bagcollects.bag_id', '=', 'bags.id')
        ->select('bags.type')
        ->where('bagcollects.bag_id', $request->input('bag_id'))
        ->first();

   //this query produce error
    $processexist = Process::join('bags', 'processes.bag_id', '=', 'bags.id')
        ->where('bags.type', $bag->type)
        ->whereDate('processes.created_at', Carbon::today())
        ->latest()
        ->first();
Run Code Online (Sandbox Code Playgroud)

php mysql laravel laravel-5.5

2
推荐指数
2
解决办法
1827
查看次数

如果选择第一个选项,jQuery将多选所有值

如果选择了第一个选项"全部",那么我想确保选中所有剩余的选项.如果未选中第一个选项"全部",则我希望确保取消选中所有剩余选项.

它似乎是选择值,但不检查前端的选项.

Codeply示例:https://www.codeply.com/go/ExFJtHShnF

我写过的Jquery代码 - 不能正常工作

$("#basic").change(function () {   
    if ( $("#basic option:first").prop('selected') ) {
        $('#basic option').prop('selected', true);
    }
});
Run Code Online (Sandbox Code Playgroud)

c# jquery

2
推荐指数
1
解决办法
984
查看次数