$(document).ready() 中的 str.split() 不起作用?
$(document).ready(function() {
var mystring="fusioncharts,om,bdutt";
var arr = mystring.split(','); //array returned
for(var i = 0; i < arr.length; i++) {
alert(arr[i]);
}
}
上面的代码可以工作吗?
编辑---
嗯,真正的代码块是这样的:
handle1 = getUrlVars();
if(handle1 == '') {
$("input#handle1").val('barackobama');
$("input#handle2").val('aplusk');
$("input#handle3").val('charliesheen');
handle1 = 'barackobama,aplusk,charliesheen';
} else {
alert(handle1); // this says fusioncharts,om,bdutt
var queryvals = [];
queryvals = handle1.split(',');
alert('length'+queryvals.length); // *** this says nothing ***
for(var i = 0; i < queryvals.length; i++) {
alert(queryvals[i]); // *** nothing here too.. ****
}
}
整个块都在 $(document).ready()...
一定是一些我无法发现的简单错误..
$(document).ready(function() {
var mystring="fusioncharts,om,bdutt";
var arr = mystring.split(','); //array returned
for(var i = 0; i < arr.length; i++) {
alert(arr[i]);
}
}
Would the above code work ?
EDIT---
Well the real code block is this :
handle1 = getUrlVars();
if(handle1 == '') {
$("input#handle1").val('barackobama');
$("input#handle2").val('aplusk');
$("input#handle3").val('charliesheen');
handle1 = 'barackobama,aplusk,charliesheen';
} else {
alert(handle1); // this says fusioncharts,om,bdutt
var queryvals = [];
queryvals = handle1.split(',');
alert('length'+queryvals.length); // *** this says nothing ***
for(var i = 0; i < queryvals.length; i++) {
alert(queryvals[i]); // *** nothing here too.. ****
}
}
And the entire block is in a $(document).ready()...
Must be some simple error which I'm unable to spot..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了它工作正常之外,你缺少右括号
you are missing the closing parentheses other than that it works fine
结束示例
是的,但是您必须使用http://jsfiddle.net/gMU9t/
Yes, but you have to close off your example with
http://jsfiddle.net/gMU9t/
你忘了关闭括号,已经拉响了警报。在询问之前调试您的代码。 JavaScript 函数运行良好。你需要更加细心。
You forgot to close your parentheses and already have sounded the alarm. Debug your code before asking. Javascript functions work fine. You need to be more attentive.