小编Ror*_*san的帖子

使用setTimeout添加和删除类

我想根据时间在div中添加和删除一个类.它应该在6秒后添加一个类,并在4秒后将其删除.我尝试了一个基本的实现.为什么不起作用?我假设问题是两个setTimeout一起像这样.如果我注释掉第二行,那么第一行就可以了.这里发生了什么?

setTimeout(addHighlight(), 6000);
setTimeout(removeHighlight(), 10000);
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何在一个delay参数的基础上编写一个同时执行这两个功能(添加和删除类)的函数吗?

javascript jquery settimeout

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

从内部调用函数on()

我需要从on()处理程序中调用一个函数.在我的示例代码中,我必须调用func1().我用的on()#myid不会对文件的负载存在.这是代码:

func1: function (e, data) {
  console.log('func1');
  this.func3();
},
func2: function (e, data) {
  $('#myid').on('click', function () {
    this.func1();
  });
}
},
Run Code Online (Sandbox Code Playgroud)

此代码不起作用.错误是:

未捕获的TypeError:this.func1()不是函数

如何从内部调用函数on()

jquery

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

如何使这个jquery countUP使用格式化的数字?

我有一个jQuery计数器,工作得很好.唯一的问题是,当我有一个data-target格式化的数字(例如,10,000而不是10000),它不起作用和显示NaN.

我不知道要修改什么,所以它也很重要,10,000,000而且不仅适用于10000000.

$('.counter').each(function() {
  var $this = $(this),
    countTo = $this.attr('data-count');

  $({
    countNum: $this.text()
  }).animate({
    countNum: countTo
  }, {
    duration: 8000,
    easing: 'linear',
    step: function() {
      $this.text(Math.floor(this.countNum));
    },
    complete: function() {
      $this.text(this.countNum);
      //alert('finished');
    }
  });
});
Run Code Online (Sandbox Code Playgroud)
body {
  background-color: #F46A6A;
  color: #fff;
  max-width: 800px;
  margin: 100px auto 0;
  text-align: center;
  display: table;
}

.counter {
  display: table-cell;
  margin: 1.5%;
  font-size: 50px;
  background-color: #FF6F6F;
  width: 200px;
  border-radius: 50%;
  height: …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

无法解析包含unicode十六进制字符的JSON字符串

var mystring = '{"Customers":[{"CustomerCity":"Zaragoza","CustomerFName":"Ana","CustomerAddress":"C/ El Temple, 9 2\\xbaB","CustomerCountry":"es"}]}';

var myparsestring = JSON.parse(mystring);
Run Code Online (Sandbox Code Playgroud)

错误:

JSON中出现意外的标记x

javascript jquery json

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

无法显示jquery ui滑块的值

当我试图显示我的滑块的值时,它不起作用?

<div class="hoogte hoogte2">
  <label for="kpa2_rating_value">Rating 2:</label>
  <div id="2" class="slider2" style="margin-bottom: 10px; margin-top: 10px;"></div>
  €<input id="productprijs" type="text" class="kpa2_rating_value" name="kpa2_rating" value="0" style="border: none;" />
</div>
Run Code Online (Sandbox Code Playgroud)
$(".slider2").slider({
  change: function( event, ui ) {
    $("#dom_element").text(value);
  }
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

无法动态地在表中添加新行

我试图在用户端的表中添加新行.我已经完成了,但它只是第一次进入新行,当你第二次点击添加行按钮时,没有任何反应.

function insTableRow(tableID) {
  var x = document.getElementById(tableID);
  var get_row = x.rows[2];
  get_row.style.display = '';
  console.log(get_row);
  $("#" + tableID + " tbody").append(get_row);
}
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<i id="add" class="fa fa-plus-circle fa-2x fa-fw" onclick="insTableRow('educationTable')"></i>
<table class="table table-responsive table-bordered order-list" id="educationTable">
  <thead>
    <tr>
      <th>Institute Name</th>
      <th>Qualification</th>
      <th>Admission Date</th>
      <th>Graduation Date</th>
      <th>Degree Scanned Image</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type="text" class="form-control" name="txt[]" id="number" /></td>
      <td><input type="text" class="form-control" name="txt[]" id="number" /></td>
      <td><input type="text" class="form-control" name="txt[]" id="number" /></td>
      <td><input type="text" class="form-control" …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

解释为什么这个HTML只适用于Firefox,而不适用于任何其他浏览器?

大家.我在HTML/CSS/Javascript中大约一周大的初学者.我为一个页面编写了这个代码,该页面用于在鼠标在页面上移动时根据"随机"RGB值(始终为alpha值固定为1)更改颜色.

<!DOCTYPE html>
<head>
  <script src='https://code.jquery.com/jquery-1.10.2.js'></script>
</head>
<body>
  <script>
    $('*').mousemove(function() {
      var red = Math.floor(Math.random() * 255);
      var green = Math.floor(Math.random() * 255);
      var blue = Math.floor(Math.random() * 255);

      var rgba = 'rgba(' + red + ',' + blue + ',' + green + ')';
      $('*').css('background', rgba);
    });
  </script>
</body>
Run Code Online (Sandbox Code Playgroud)

我尝试过Chrome,Chromium,Vivaldi,Opera甚至是Internet Explorer,所有这些浏览器都显示了一个网页,其默认的白色背景页面对鼠标移动没有反应.

html javascript css jquery

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

Using Jquery's .each() function makes the web page lag on mobile devices

When I click on a span or div element the audio is played. The function also contains .each() to prevent the audios from overlapping each other, that is, when a user clicks a word, the audio is played and when a user clicks on another word, the current audio stops playing and the new audio is played.

The problem is, I have over a thousand span or div elements on some of my pages and while the web page works …

html javascript jquery

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

在字符串中查找子字符串

让我们说我有这些字符串:

My dog is young  

I have a _dog_ 

Dogs are fine
Run Code Online (Sandbox Code Playgroud)

我想有任何字符串dog唯一.这意味着我只想要返回第一行.另外两个,包含_我不想要的标记,或者最后有额外的标记s.

我尝试过这样的事情:

$('#side-categories a').each(function () {
    var href = $(this).attr("href");
    if (href.indexOf(table) >= 0) {
        $(this).css("color", "red");
        $(this).parents("ul").show().prev('.do').text('-');
    }
});
Run Code Online (Sandbox Code Playgroud)

但它也会返回_dog_Dogs

建议?

javascript jquery

0
推荐指数
1
解决办法
100
查看次数

在JQuery中使用JSON数组

我有一个宁静的Web服务http:// localhost:8080/CRUDWebAppMavenized/persons,输出一个json数组.我在jquery中使用AJAX,我想在我的HTML表中显示json数组.我不能让它显示在html表中.我将发布html,javascript代码和json数组代码.

index3.html HTML文件.用于在浏览器中显示学生信息.

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="engine.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    </head>
    <body>
        <table id="blogTable">
            <tr>
                <th>studentId</th>
                <th>firstname</th>
                <th>lastname</th>
                <th>yearLevel</th>
            </tr>
        </table>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

engine.js(使用Jquery) AJAX调用然后将代码放在html文件的表标记中.

$(document).ready(function () {
    $.ajax({
        url: 'http://localhost:8080/CRUDWebAppMavenized/persons',
        type: 'GET',
        dataType: 'json',
        success: function (result) {
            var insert = '';
            $.each(result, function (index, item) {
                insert += '<tr><td>' + item.studentId + '</td><td>' + item.firstname + '</td><td>' + item.lastname + '</td><td>' + item.yearLevel + '</td></tr>';
            });
            $('#blogTable tr:last').after(insert);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

JSON数组 …

html javascript ajax jquery json

0
推荐指数
1
解决办法
717
查看次数

标签 统计

jquery ×10

javascript ×9

html ×4

json ×2

ajax ×1

css ×1

settimeout ×1