请看这个小提琴:http://jsfiddle.net/yg49k/
以下代码在FireFox中正常工作,但在最新版本的Chrome中无效.
HTML:
<input type="text" id="one" placeholder="Type two chars" />
<input type="text" id="two" placeholder="It should focus here" />
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$("#one").on("input", function() {
if($("#one").val().length == 2) { $("#two").focus(); }
});
Run Code Online (Sandbox Code Playgroud)
有谁知道我怎么能解决这个问题?
我有以下Wikipedia API搜索查询:
我只是想列出名人 - 有没有办法做到这一点?
HTML:
<form>
<button type="button" class="form-clear">Clear</button>
<button type="button" class="form-set">Set</button>
<input type="text" value="Preset value" />
<input type="checkbox" checked/>
<input type="checkbox" />
</form>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(".form-clear").click(function(){
$(':input').not(':button, :submit, :reset, :hidden').val('');
$(':checkbox, :radio').attr('checked', false);
});
$(".form-set").click(function(){
$(':input').not(':button, :submit, :reset, :hidden').val('New preset value');
$(':checkbox, :radio').attr('checked', true);
});
Run Code Online (Sandbox Code Playgroud)
我猜这两个函数之间有冲突吗?
我有这个代码:
$text = "Line 1
Line 3";
$n = explode("\r", $text);
Run Code Online (Sandbox Code Playgroud)
如果我回声$n[1](第2行)我得到一个空格.但$n[1] == " "回报false.
那个角色是什么?
经过进一步的研究,我应该真正使用:
$n = preg_split("/\r\n|\n|\r/", $text);
Run Code Online (Sandbox Code Playgroud) 我的理解switch()是它避免重复字符串.
如果是这样,为什么它不支持正则表达式,如下面的代码?或者我错过了什么意思switch()?
switch($username){
case "":
array_push($errors, "Username cannot be blank");
break;
case "admin":
array_push($errors, "Username cannot be 'admin'");
break;
case regex_switch('/xxx.*/'):
array_push($errors, "Username cannot begin 'xxx'");
break;
}
Run Code Online (Sandbox Code Playgroud)