小编Pra*_*man的帖子

JQuery - 在悬停时替换图像

我有一个图像文件夹.在这个文件夹中,我有两种类型的图像; 一个png一个gif.显示的图像是png版本.在图像悬停时,我需要将其替换为其gif版本.当悬停时,将png版本放回原位.

我目前有以下工作

$(".image-container").mouseover(function () {
    var imgName = $(this).find('img').attr('src');
    var img2 = imgName.substring(0, imgName.lastIndexOf("."));
    $(this).find('img').attr("src", img2+".gif");
}).mouseout(function () {
    var imgName = $(this).find('img').attr('src');
    var img2 = imgName.substring(0, imgName.lastIndexOf("."));
    $(this).find('img').attr("src", img2+".png");
});
Run Code Online (Sandbox Code Playgroud)

它有效,但我不喜欢我重复的方式.有没有办法让这个更有效率?

谢谢

jquery

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

C递归函数找到最小值

我正在写一个程序:

例如,输入是5(它不仅可以是5个)数字,我在数组中读取数据:1, 2, 3, 4, 5.我可以从这个数组中选择一些元素(不是第一个或最后一个),例如3,然后我在数组中删除这个数字,并且sum(最初为0)添加首先左到右加第一个到 -正确的元素(2*4在这种情况下意味着).结果数组是1, 2, 4, 5,然后我一次又一次地做,直到元素数等于2(1 and 5正如我们不能删除这些数字).

例如:(其中A,B,C,D是数字对1和2,2和3等对.)

 A B C D
1 2 3 4 5
Run Code Online (Sandbox Code Playgroud)

订单删除元素有6种可能的组合(并将左右乘法加到sum):

A (B (C D))
A ((B C) D)
(A B) (C D)
(A (B C)) D
((A B) C) D
A (B (C D))
Run Code Online (Sandbox Code Playgroud)

目标是找到最小的总和!有两种解决方法,一些聪明的算法或每种组合使用递归,然后选择最小的一种.任何人都可以给我一个提示如何编写这样的递归,从哪里开始编写(或者可能是一些聪明的算法).TNX

c algorithm

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

JavaScript数组长度的错误表示

如果我在JavaScript中有一个数组,请说:

var a = [1, 2, 3];
var b = ["Praveen", "Kumar", "Stack", "Overflow"];
Run Code Online (Sandbox Code Playgroud)

如果我得到上述数组的长度:

a.length;
b.length;
Run Code Online (Sandbox Code Playgroud)

我得到了正确的值.即

a.length;  // 3
b.length;  // 4
Run Code Online (Sandbox Code Playgroud)

但是,如果我创建另一个数组,我将索引设置为:

c = [];
c[5] = "Five";
c[10] = "Ten";
Run Code Online (Sandbox Code Playgroud)

然后,如果我查询长度,它会告诉我11.

c.length  // 11
Run Code Online (Sandbox Code Playgroud)

这是错的吗?或者这样JavaScript解释数组?请指导.

javascript arrays

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

列表复选框水平显示

我有以下标记: -

<div class="fil hori now">
  <span class="label-new">
    <ul class="ngc">
      <li>
        <input class="any" id="any" name="any" type="checkbox"> 
        <label id="any" for="any">Any</label>
      </li>

      <li class="new-select">
        <input id="item1" name="item1" type="checkbox">
        <label id="item1" for="item1">item1</label>
      </li>

      <li class="new-select">
        <input id="item2" name="item2" type="checkbox">
        <label id="item2" for="item2">item2</label>
      </li>

      <li class="new-select">
        <input id="item3" name="item3" type="checkbox">
        <label id="item3" for="item3">item3</label>
      </li>
    </ul>

  </span>
</div>
Run Code Online (Sandbox Code Playgroud)

我如何使项目列表水平,但如果我有新项目,他们只是以特定宽度而不是一行进入下一行?

html css html5 css3 twitter-bootstrap

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

如何划分表格以分页显示?表格数据用jsp动态填充

我有一个使用HTMLand创建的表JSP。表的值是使用 JSP 动态创建的。我的代码类似于下图所示:

<link rel="stylesheet" type="text/css" href="css/table.css">
<HTML>
<BODY>
<div class="MyTable" >
<table border="0">
<thead>
<tr>
    <td><b>User</b></td>
    <td><b>Data</b></td>
</tr>
</thead>
<%

-----------------------
--- JAVA CODE ---------
-----------------------
if( condition )  //if condition satisfied, then a row of data is added
{
%>
<tr>
    <td><%= GENERATED_FROM_CODE %></td>
    <td><%= GENERATED_FROM_CODE %></td>
</tr>
<%
}
-----------------------
--- JAVA CODE ---------
-----------------------
%>
</BODY>
<HTML>
Run Code Online (Sandbox Code Playgroud)

有时数据很大,表变得很长。我想创建一个页面,其中只显示某个数字,比如一次显示10 行。应该有下图给出了一个链接下一/先前第一/最后页面 数量等,这将让你在表中的内容浏览。 …

html javascript css jquery jsp

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

CSS类恢复为非活动状态

我正在为图像添加一个类.

.bbbLink img { 
    outline: 1px solid #ddd;
    border-top: 1px solid #fff;
    padding: 10px;
    background: #f0f0f0;
}
Run Code Online (Sandbox Code Playgroud)

在悬停时我添加了这个,

.bbbLink img:hover { 
    background-color: rgba(0, 0, 0, 0.1);
    outline: 1px solid #ddd;
    border-top: 1px solid #fff;
    padding: 10px;
    background: #f0f0f0;
}
Run Code Online (Sandbox Code Playgroud)

为了活跃,我这样做,

.bbbLink img:active {
    outline: 1px solid #111 !important;
    border-top: 1px solid #555 !important;
    padding: 10px !important;
    background: #333 !important;
}
Run Code Online (Sandbox Code Playgroud)

因为我将活动类添加到图像而你不能这样做,因为它是一个自我关闭元素我使用jquery来处理像这样添加活动状态,

<script>
(function($) {
$('.bbbLink').click(function() {
    $(this).toggleClass('active');
});
})( jQuery );
</script>
Run Code Online (Sandbox Code Playgroud)

即使在单击我的活动类出现的元素后检查dom时,一切都很完美.

<a id="wrapbbb" class="bbbLink active" href="img.jpg" target="_blank">
<img …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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

将jquery datatable数据转换为json

我正在使用jquery数据表。我有一张桌子如下

<table id="employees">
  <thead>
     <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>
        <th>Phone</th>
      </tr>
    </thead>
   <tbody>
      <tr>
           <td>1</td>
           <td>Karthik</td>
           <td>Kk@gmail.com</td>
           <td>1234</td>
       </tr>
       <tr>
           <td>1</td>
           <td>Karthik</td>
           <td>Kk@gmail.com</td>
           <td>1234</td>
       </tr>
     </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

我将表转换为jquery datatable作为 $('#employees').DataTable()

我想将我的jquery数据表转换为json格式。请帮助我将其转换为

[{"Id":"1", "Name":"Karthik","Email":"kk@gmail.com","Phone":"1234"}]
Run Code Online (Sandbox Code Playgroud)

jquery json datatables

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

将数据写入本地JSON文件

我将JSON文件存储在资产文件夹中。从中读取是很容易的,但是如何写入它以及退出应用程序时是否保存了数据?

JSON:

{
    "Home": [
        {
            "Task": "Lapup1",
            "Time": "14:00",
            "Date": "26/12/2016"
        },
        {
            "Task": "Lapup2",
            "Time": "17:00",
            "Date": "26/12/2016"
        },
        {
            "Task": "Lapup3",
            "Time": "15:00",
            "Date": "26/12/2016"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

杰森·帕瑟(阅读):

public class JSONParser {

    ArrayList<Task> taskList;
    String json;

    public JSONParser(Context context) {
        taskList = new ArrayList<Task>();
        json = null;
        try {
            InputStream is = context.getAssets().open("Home.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        } …
Run Code Online (Sandbox Code Playgroud)

android json

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

使用 jQuery 检查值是否为 null

我试图检查变量的值是否为空,但它不起作用。我还必须停止脚本并且不要插入行

网页

<input type="text" name="for_intitule" id="form_intitule">
Run Code Online (Sandbox Code Playgroud)

jQuery

var form_intitule = $('input[name=form_intitule]').val();

if(form_intitule == null){
  alert('fill the blank');
  return false;
}
Run Code Online (Sandbox Code Playgroud)

更新 :

$('#insertForm').on('click', function(){
  var form_intitule = $('input[name=form_intitule]').val();

  if($('input[name=form_intitule]').val().trim().length == 0){
    alert('fill the blank');
  }
  $.ajax({
    type: "GET",
    url: "lib/function.php?insertForm="+insertForm+"&form_intitule="+form_intitule,
    dataType : "html",
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
    },
    success:function(data){
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

jquery

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

Node.js:如何使用fs.createWriteStream创建具有755权限的文件

我需要在节点中使用哪个标志fs.createWriteStream来创建具有755权限的文件.

javascript fs node.js

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

标签 统计

jquery ×5

javascript ×4

css ×3

html ×3

json ×2

algorithm ×1

android ×1

arrays ×1

c ×1

css3 ×1

datatables ×1

fs ×1

html5 ×1

jsp ×1

node.js ×1

twitter-bootstrap ×1