我正在 iOS 中构建一个混合应用程序,我需要在我的 HTML 页面中单击已加载到我的 webview 中的控件来打开日期选择器。以下是该特定控件和相关 javascript 方法的 HTML:
<input name="date" id="creationDate" class=dateET type="date" onclick="onDateSelected();" readonly />
function onDateSelected()
{
console.log('onDateSelected');
var dateOn = document.getElementById('creationDate').value;
document.location.href = "#mCrm#onDateSelected#mCrm#"+dateOn;
}
在目标 C 中:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *requestString = [[request URL]absoluteString];
if (!([requestString rangeOfString:@"onDateSelected"].location == NSNotFound))
{
[self onDateSelected:requestString];
return FALSE;
}
else if (!([requestString rangeOfString:@"onAddCustomerBtnClick"].location == NSNotFound))
{
}
return TRUE;
}
-(void)onDateSelected:(NSString *)reqString
{
custDate = [[UIDatePicker alloc] init];
custDate.datePickerMode = UIDatePickerModeDate;
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
[toolbar sizeToFit];
//to make the done button aligned to the right
UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* doneButton = nil;
// if(sender == self.mCdob)
doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self
action:@selector(doneDateOfBirth:)];
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, doneButton, nil]];
//custom input view
// sender.inputView = datePickerContact;
// sender.inputAccessoryView = toolbar;
}
问题是单击日期类型输入控件时,日期选择器未打开。欢迎任何帮助!