使用以下代码,我在thisRange.setStart行上得到一个INDEX_SIZE_ERR:DOM异常1错误.代码用于遍历整个页面,查找searchString的实例,然后在该搜索字符串前面添加一个链接.例如,如果它找到了5个字符串实例,那么现在它将在第一个字符串前面添加链接,但在第二个字符串上添加错误并停止,留下四个没有链接的单词.有任何想法吗?
if(searchString.length > 0) { // make sure the string isn't empty, or it'll crash.
// Search all text nodes
for(var i = 0; i < textNodes.length; i++) {
// Create a regular expression object to do the searching
var reSearch = new RegExp(searchString,'gmi'); // Set it to 'g' - global (finds all instances), 'm' - multiline (searches more than one line), 'i' - case insensitive
var stringToSearch = textNodes[i].textContent;
while(reSearch(stringToSearch)) { // While there are occurrences of the searchString …Run Code Online (Sandbox Code Playgroud) 我创建了一个小示例HTML页面,以使JQuery的getJSON方法正常工作.它看起来像下面(对不起,这只是一个概念证明,然后加入一个更大的项目):
<script type="text/javascript">
function test() {
$.getJSON("http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=e999b3a5d47d013b780e8ac255c86266&user_id=24579658@N03&format=json&jsoncallback=?",
function(data){
$.each(data.photos.photo, function(i,photo){
$("<img/>").attr("src", "http://farm5.static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + ".jpg").appendTo("#images2");
//alert();
if ( i == 6 ) return false;
});
});
Run Code Online (Sandbox Code Playgroud)
}
然后我会在点击某些内容时调用该方法
<script type="text/javascript">
$(function() {
$("#yo").click(test);
});
</script>
Run Code Online (Sandbox Code Playgroud)
这在一个项目中运行良好,其中包含的唯一JS是JQuery,这些是唯一的功能.但是,一旦我将它添加到我的其他项目中,它就会出错.另一个项目包括一些mootools库,我认为可能已经这样做了.然而,即使在完全删除了mootools之后,只使用了这个jquery的东西,我仍然会得到以下错误:
ReferenceError:$未定义
我确实包含了其他javaScripts,例如谷歌和其他一些我已经制作的,但他们不使用JQuery或Mootools.谁能解释为什么我会收到这个错误?
我知道您可以使用Interface Builder中的"Inset"属性使滚动视图从主窗口插入,以便它不会低于屏幕上的现有控件(如标签栏),但是如何以编程方式执行此操作调整键盘何时添加到屏幕?目前我的滚动视图在键盘下方有单元格无法访问,因为视图仍然将滚动视图的底部注册为手机底部,而不是键盘顶部.有帮助吗?
我目前有一个UINavigationController的子类,它具有以下viewDidLoad函数.
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"HI"
style:UIBarButtonItemStylePlain
target:self
action:@selector(manage)];
[self.navigationItem setLeftBarButtonItem:leftButton];
[self.navigationBar setBackgroundImage:[[UIImage imageNamed:@"top_nav_bg.png"] stretchableImageWithLeftCapWidth:3.0 topCapHeight:0.0] forBarMetrics:UIBarMetricsDefault];
}
Run Code Online (Sandbox Code Playgroud)
UINavigationController子类是UITabBarBarController子类中的一个选项卡,具有以下viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
// Change some of the look of the main tab bar
[self.tabBar setBackgroundImage:[[UIImage imageNamed:@"tab_nav_bg.png"] stretchableImageWithLeftCapWidth:2.0 topCapHeight:0.0]];
[self.tabBar setSelectionIndicatorImage:[[UIImage imageNamed:@"tab_nav_bg_active.png"] stretchableImageWithLeftCapWidth:2.0 topCapHeight:0.0]];
// Load the various view controllers for this view
SBHomeViewController *homeViewController = [[SBHomeViewController alloc] init];
[homeViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_home_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_home.png"]];
[homeViewController.tabBarItem setImageInsets:UIEdgeInsetsMake(5.0, 0.0, -5.0, 0.0)];
// The navigation controller …Run Code Online (Sandbox Code Playgroud) iphone uitabbarcontroller uinavigationcontroller uinavigationitem
我正在尝试提出一种算法来查找文本正文中的URL.我目前有以下代码(这是我坐下来破解代码,我知道必须有更好的方法):
statusText.text = @"http://google.com http://www.apple.com www.joshholat.com";
NSMutableArray *urlLocations = [[NSMutableArray alloc] init];
NSRange currentLocation = NSMakeRange(0, statusText.text.length);
for (int x = 0; x < statusText.text.length; x++) {
currentLocation = [[statusText.text substringFromIndex:(x + currentLocation.location)] rangeOfString:@"http://"];
if (currentLocation.location > statusText.text.length) break;
[urlLocations addObject:[NSNumber numberWithInt:(currentLocation.location + x)]];
}
currentLocation = NSMakeRange(0, statusText.text.length);
for (int x = 0; x < statusText.text.length; x++) {
currentLocation = [[statusText.text substringFromIndex:(x + currentLocation.location)] rangeOfString:@"http://www."];
if (currentLocation.location > statusText.text.length) break;
[urlLocations addObject:[NSNumber numberWithInt:(currentLocation.location + x)]];
}
currentLocation = NSMakeRange(0, …Run Code Online (Sandbox Code Playgroud) iphone ×2
algorithm ×1
dom ×1
getjson ×1
javascript ×1
jquery ×1
json ×1
mootools ×1
nsrange ×1
objective-c ×1
range ×1
sdk ×1
uitableview ×1
url ×1