伙计们当我点击一个按钮并制作该代码时,我试图获取随机值,但当我点击某种方式时,一个值重复4次,如" k0k2k4k6" ," n0n2n4n6"。 为什么会发生这种情况?这不是巧合。 提前致谢! JSFIDDLE
private AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder( ).
setConnectTimeout( 20000 ).
setRequestTimeout( 20000 ).
setWebSocketTimeout(20000).
setMaxRequestRetry(3).
setReadTimeout( 20000 ).
setAcceptAnyCertificate( true ).
build( )
private AsyncHttpClient = new AsyncHttpClient( cfg )
client.prepareGet( url ).
setProxyServer( new ProxyServer( ProxyServer.Protocol.HTTP, "myproxyurl", 2222, "principal", "password" ) ).
execute( ).
get()

$(function() {
var words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
var word = words[Math.floor(Math.random() * words.length)];
var myLength = 8;
function random() {
for (var i = 0; i < myLength; i++) {
$('#content').append(word + i++);
}
}
$('#button').click(function() {
random();
});
});
&#13;
#content {
width: 200px;
height: 50px;
border: 1px solid #333;
margin-top: 50px;
&#13;
答案 0 :(得分:3)
为什么会产生4次?
因为你的最大限制是8而你正在递增两次,一个在word
循环中,在那里。
在循环中移动$(function() {
var words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
var myLength = 8;
function random() {
// Also I would clear before generating new:
$('#content').html("");
for (var i = 0; i < myLength; i++) {
var word = words[Math.floor(Math.random() * words.length)];
$('#content').append(word + i++);
}
}
$('#button').click(function() {
random();
});
});
(生成的动态)定义解决了它:
#content {
width: 200px;
height: 50px;
border: 1px solid #333;
margin-top: 50px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="button">Click</button>
<div id="content"></div>
pattern = """
P2: {<JJ>+ <RB>? <JJ>* <NN>+ <VB>* <JJ>*}
P1: {<JJ>? <NN>+ <CC>? <NN>* <VB>? <RB>* <JJ>+}
P3: {<NP1><IN><NP2>}
P4: {<NP2><IN><NP1>}
"""
答案 1 :(得分:0)
将变量移动到函数中:
JasperPrint
答案 2 :(得分:0)
试试这个
$(function() {
var words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
var myLength = 8;
function random() {
var word = words[Math.floor(Math.random() * words.length)];
for (var i = 0; i < myLength; i++) {
$('#content').append(word + i++);
}
}
$('#button').click(function() {
$('#content').html('');
random();
});
});