小编Car*_*los的帖子

循环在JavaScript中无法正常工作

我想选择我的HTML中有多少div.所以我用.length方法,但它没有给我欲望的结果.你可以在这里看一个演示http://jsfiddle.net/WbwuC/

<style>

.main { width:980px; margin:0 auto; border:solid 1px #F00; overflow:hidden}

.box { width:300px; float:left; margin-right:20px; background:#00F; height:200px;}
.new {border:solid 2px #333;}

</style>


<script type="text/javascript">


    var amy= document.getElementsByTagName('div');

    for (i=0;i<amy.length;i++){
        var jar= amy[i];
        }
     alert(jar)


</script>

</head>

<body>
<div id="main">
<div class="box"><h3>first</h3></div>
<div class="box"><h3>secnond</h3></div>
<div class="box"><h3>third</h3></div>

</div>

</body>
Run Code Online (Sandbox Code Playgroud)

html javascript

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

javascript document.createElement函数?

我有一个变量,其中包含3个标记名称,它们之间用","字符分隔.我想用.split()函数将它们拆分为appart,然后创建并将3个元素附加到文档正文.

<head>
<style>
div { height:500px; width:500px; background:#F00; float:left}   
span{display:block; float:right}   
</style>

<script type="text/javascript">

var element= div,p,span;    
var j=element.split(',')

for(i=0;i<j.length;i++){            
    var crt=document.createElement(j[i])
}

document.body.append(crt)

</script>    
</head>    
<body>
</body>
Run Code Online (Sandbox Code Playgroud)

html javascript

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

如何使用jquery添加类

我做了一个小函数,当我们点击li时,我的工作是在li中添加类,但是如果它已经与li一起删除了.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
    <meta name="created" content="Tue, 22 May 2012 12:39:23 GMT">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title></title>

    <style type="text/css">
    <!--
    body {
      color:#000000;
      background-color:#FFFFFF;
    }
    a  { color:#0000FF; }
    a:visited { color:#800080; }
    a:hover { color:#008000; }
    a:active { color:#FF0000; }
    -->
    </style>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

    <script type="text/javascript">

    $(function(){

    $('.main').find('li').each(function(){

    $(this).live('click', function (){

    $(this).addClass('active')

    })

    })

    })

    </script>

  </head>
  <body>

  <ul …
Run Code Online (Sandbox Code Playgroud)

css jquery

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

如何使用 jquery 设置顶部父元素的样式

我想要样式顶级父级,它应该是动态的。我只想要风格顶级的父母。我们可以添加更多的父 div,但样式应该反映到 div。jquery可以做到吗?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">

$(function(){
    $('.text').parent().css('background-color','red')
})

</script>
</head>
<body>

<div>
    <div>
        <div class="menu">
            <div class="text">hiiii</div>
        </div>
    </div>
</div>

</body>
Run Code Online (Sandbox Code Playgroud)

jquery

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

文字对齐在CSS中继承

我有一个HTML结构,其中包含div和一些CSS规则。我想知道为什么text-align:centre继承给它的子div,为什么只有text-align:centre继承

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style>


.multi{ width:500px; text-align:center; float:left }
</style>

</head>

<body>

<div class="multi">
<div class="rr">Abc</div>
</div>

</body>
Run Code Online (Sandbox Code Playgroud)

html css

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

.is(':visible')在jQuery中不起作用

.is(':visible')在jquery中使用方法但它没有按预期工作.

这是我的代码片段

我在那里错过了什么?

HTML:

<div class="str">

    <ul><li>1</li><li><a href="#">hide</a></li></ul>
    <ul><li>2</li><li><a href="#">hide</a></li></ul>
    <ul><li>3</li><li><a href="#">hide</a></li></ul>
    <ul><li>4</li><li><a href="#">hide</a></li></ul>
    <ul><li>5</li><li><a href="#">hide</a></li></ul>
    <ul><li>6</li><li><a href="#">hide</a></li></ul>

    <div class="length"></div>

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

jQuery的:

$(function(){

    $('.str ul').find('a').live('click',function(){
       $(this).closest('li').parent().hide();
       var ll= $('.str').find('ul').each(function(){  
           $('.length').text( $('.str').find('ul').is(':visible').length );  
        });   
    });

});
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

正则表达式javascript中$ 1

当我使用var j= new RegExp('('+val+')','gi')然后$1工作正常.但是当我在没有支架的情况下使用它时它就不起作用了.所以我想知道为什么括号是必要的并且确实$1保留了必须被替换的值?

var val='city'
var j= new RegExp('('+val+')','gi')
console.log(j)
$('div').html(function(i,val){
return val.replace(j,'<span>$1</span>')
})
Run Code Online (Sandbox Code Playgroud)

javascript regex

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

在 React Native 中缩放图像

像 HTML 中那样缩放图像。img {height:100%; width:100%}在本机反应中。

我已经尝试过resizeMode?: enum('cover', 'contain', 'stretch', 'repeat', 'center'),但它们都不适合我的情况。

<View style={{
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    flexDirection:'row'
  }}>
        <View style={{flex:1, backgroundColor:'yellow'}}>
        <Image
          style={{width: 50, height: 50}}
          resizeMode="stretch"
          source={{uri: 'http://aristotlebuzz.com/wp-content/uploads/2017/01/Facebook.png'}}
        />
        </View>
        <View style={{flex:1, backgroundColor:"red"}}>
           <Text>afdafda</Text>
        </View>

      </View>
Run Code Online (Sandbox Code Playgroud)

https://snack.expo.io/ByhjFQo1M

react-native

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

在CSS中删除具有动画效果的行

我想用某种动画删除该行.问题是当我将宽度设置为0然后它也改变了它的位置.这不应该发生.

该线应从起点移动到终点而不改变其位置.

$('button').click(function(){
$('.main').toggleClass('remove')
})
Run Code Online (Sandbox Code Playgroud)
.line{
  width:60px;
  height:2px;
  background:#000;
  transform: rotate(30deg);
  position:absolute;
  top:20px;
  z-index:1;
  transition: all 0.3s ease-in-out;
}

.remove .line{
  width:0
}
.main{
  position:relative;
}
span{
  display:inline-block;
  width:40px;
  height:40px;
  background:red;
  border-radius:50%;
  position:relative;
  left:8px;
  top:2px
}

button{
  margin-top:60px
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
<div class="line"></div>
<span></span>
</div>

<button>toggle</button>
Run Code Online (Sandbox Code Playgroud)

小提琴

html css jquery css-animations

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

Promise.resolve 从笑话模拟函数返回未定义

我有一个函数可以进行 API 调用,并根据第一个 API 调用返回的内容进行第二个 API 调用。但第一个API总是返回undefined

getTotalCount = async () => {
    const { showCountCallBack, showCount } = this.props;
    try {
      const response = await showCount();

      const count = isEmpty(response.result);

      if (count) {
        console.log(" success");
      } else {
        showCountCallBack({ ...this.state });
      }
    } catch (e) {
      console.log("error");
    }
  };
Run Code Online (Sandbox Code Playgroud)

describe("component", () => {
  let shallowComponent;
  let shallowComponentInstance;
  const showCountMock = jest.fn(() => Promise.resolve({ result: [] }));

  const showCountCallBackMock = jest.fn(() => Promise.resolve({ result: [] }));

  beforeEach(() => {
    showCountMock.mockReset(); …
Run Code Online (Sandbox Code Playgroud)

jestjs enzyme

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

标签 统计

html ×5

javascript ×4

jquery ×4

css ×3

css-animations ×1

enzyme ×1

jestjs ×1

react-native ×1

regex ×1