2017-02-15 6 views
1

私はランダムに1つのサイドを削除しようとしています。 しかし、私はそれを働かせるように見えることはできません。 Javaにはまったく新しいので、私は多くの経験がありません。divから1つのボーダーサイドを無作為に削除

コード:私は得ることができるすべての助けを

$(document).ready(function() { 
var exitCards = ['top', 'right', 'bottom', 'left']; 
    $('.exit-card').each(function() { 
     $(this).css('border-', + exitCards[Math.floor(Math.random() * exitCards.length)], '0 none'); 
    }; 
    }; 

感謝。

+0

あなたのhtml CSSコードも投稿してください –

+0

''border-''の後にカンマを削除してみてください。 –

+0

作業中[Fiddle](https://jsfiddle.net/bRIMOs/bgd5e3z9/) –

答えて

4

、ちょうど1 ,

$(this).css('border-', +exitCards[Math.floor(Math.random() * exitCards.length)], '0 none'); 
        ^
        Remove this 

を移動する。また、あなたの()を閉じるのを忘れそう};}); する必要があります。これ、あなたは2回

を忘れてしまいました

$(document).ready(function() { 
 
    var exitCards = ['top', 'right', 'bottom', 'left']; 
 
    $('.exit-card').each(function() { 
 
    $(this).css('border-' +exitCards[Math.floor(Math.random() * exitCards.length)], '0 none'); 
 
    }); 
 

 
});
.exit-card { 
 
    height: 50px; 
 
    width: 50px; 
 
    border: 1px solid #000; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="exit-card"></div>

+0

パーフェクト!ヘルプをよろしくお願いいたします。クイックレスポンス、素晴らしい! – Linus

+0

これが問題の解決策だった場合は、それをあなたの質問への回答としてマークすることをお勧めします。 –

0

あなたは

$(document).ready(function() { 
var exitCards = ['top', 'right', 'bottom', 'left']; 
    $('.exit-card').each(function() { 
     $(this).css('border-' + exitCards[Math.floor(Math.random() * exitCards.length)], '0 none'); 
    }); 

    }); 

チェック今 ')' 欠けている、 これは動作するはずです。

+0

パーフェクト!ヘルプをよろしくお願いいたします。 – Linus

+0

ありがとう:)私はその正常に動作していると確信しています。 – rahulsm

0
$(document).ready(function() { 
var exitCards = ['top', 'right', 'bottom', 'left']; 
    $('.exit-card').each(function() { 
    var item = "border-"+exitCards [Math.floor(Math.random()*exitCards .length)]; 
     $(this).css({item : '0px'}); 
    }; 

    }; 

使用このあなたはほとんどそれを持っていた

+0

あなたはコードが動作しません。チェック ')' – rahulsm

+0

パーフェクト!ヘルプをよろしくお願いいたします。 – Linus

関連する問題