Py学习  »  Nidhin Joseph  »  全部回复
回复总数  6
5 年前
回复了 Nidhin Joseph 创建的主题 » 按热键跳过li不工作jquery

你可以使用 document.activeElement 为了活跃起来 input 元素。一旦你得到 输入 实例,使用 closest() li next() 移动到下一个

$("li").on("click", function() {
  $("li").find("input").hide();
  $(this).find("input").show().focus();

});

$('body').keypress(function(e) {

  if (e.which == 53) {
    e.preventDefault();

    let li, input;
    if (document.activeElement.tagName == "BODY") {
      input = $('li input').first();
    } else {
      li = $(document.activeElement).closest('li');
      input = li.next().find("input");
    }

    input.show();
    input.focus();
  }
});
li input {
  display: none;
}

li {
  cursor: pointer;
  border: 1px solid red;
  margin: 5px;
  padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<ul class='list'>

  <li>a <input value='' /></li>
  <li>b <input value='' /></li>
  <li>c <input value='' /></li>
  <li>d <input value='' /></li>
  <li>e <input value='' /></li>
  <li>f <input value='' /></li>

</ul>
5 年前
回复了 Nidhin Joseph 创建的主题 » 如何使用从jquery获得的数据,然后在for循环的var中使用它?

一种方法是编写函数并将要插入的数据传递给对象。在函数内部,添加必需字段并返回数组。

var sampleData = [{
  name: 'Jon'
}, {
  name: 'Bob'
}]

var result = [{
  data: processData(sampleData)
}];

function processData(data) {
  let tmp = [];

  data.forEach(e => {
    tmp.push({
      "type": "scatter",
      toolTipContent: "<span>{name}</span><br/> Load: {x} TPS<br/> Response Time:</span> {y} ms",
      name: e.name,
    })
  });

  return tmp;
}

console.log(result);

第二种方法是使用如下的生命周期声明

var sampleData = [{
  name: 'Jon'
}, {
  name: 'Bob'
}]

var result = [{
  data: (function(data) {
    let tmp = [];

    data.forEach(e => {
      tmp.push({
        "type": "scatter",
        toolTipContent: "<span>{name}</span><br/> Load: {x} TPS<br/> Response Time:</span> {y} ms",
        name: e.name,
      })
    });

    return tmp;
  })(sampleData)
}];

console.log(result);
5 年前
回复了 Nidhin Joseph 创建的主题 » 如何快速jQuery显示元素,并在短时间内隐藏

你可以用 fadeToggle 有条件地设置切换的速度。

$('.enmenu').on('click', function() {

  var el = $('.ensettings');
  el.fadeToggle(el.is(":hidden") ? 200 : 5000);

});
5 年前
回复了 Nidhin Joseph 创建的主题 » 如何使用jquery选择器删除tr[副本]

尝试使用 arrow function 相反。这将确保作用域保留在click事件而不是 success()

$("#removebutton").on("click", function() {
  .....
  success: (res) => {
    $(this).parent().remove(); 
  }
  ....
});
5 年前
回复了 Nidhin Joseph 创建的主题 » jquery count具有值的输入字段数

从引用到 this post ,也可以创建自定义选择器,然后仅获取 input 有价值的。

jQuery.expr[':'].hasValue = function(el, index, match) {
  return el.value != "";
};

$('.input').keyup(function() {
  console.log($(this).parent().find('input:hasValue').length);
});
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<div class="row">
  <input type="text" class="input input1" />
  <input type="text" class="input input2" />
  <input type="text" class="input input2" />
</div>

<div class="row">
  <input type="text" class="input input1" />
  <input type="text" class="input input2" />
  <input type="text" class="input input2" />
</div>
6 年前
回复了 Nidhin Joseph 创建的主题 » 如何删除ol child在jquery中没有li的li元素?
if ($('#el').is(':empty')){
  // custom code
}

更多信息 here