我正在使用 Objective-C 制作一个 Mac 应用程序,我需要它能够在网站上提交表单(好吧,按一个按钮),但用户所要做的就是提供与该表单相关的时间。形式。
这是网站上的代码:
<td class=t_h>07:16</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class=t_s height='24'>
<form method="POST" action="members_booking.php?operation=member_booking_form" onSubmit="return ValidateMemberBookNow(this)">
<INPUT NAME=double_click TYPE=hidden>
<INPUT NAME=course_id TYPE=hidden VALUE="1">
<INPUT NAME=unique_id TYPE=hidden VALUE="230693">
<INPUT NAME=d_date TYPE=hidden VALUE="2012-09-07">
<INPUT NAME=Booking_Operation TYPE=hidden VALUE="Book Casual">
<INPUT NAME=SubmitButton TYPE=submit VALUE="Book Now">
</form>
</td>
</tr>
<tr>
<td class=t_h>07:24</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class=t_s height='24'>
<form method="POST" action="members_booking.php?operation=member_booking_form" onSubmit="return ValidateMemberBookNow(this)">
<INPUT NAME=double_click TYPE=hidden>
<INPUT NAME=course_id TYPE=hidden VALUE="1">
<INPUT NAME=unique_id TYPE=hidden VALUE="230694">
<INPUT NAME=d_date TYPE=hidden VALUE="2012-09-07">
<INPUT NAME=Booking_Operation TYPE=hidden VALUE="Book Casual">
<INPUT NAME=SubmitButton TYPE=submit VALUE="Book Now">
</form>
</td>
</tr>
<tr>
<td class=t_h>07:32</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class=t_s height='24'>
<form method="POST" action="members_booking.php?operation=member_booking_form" onSubmit="return ValidateMemberBookNow(this)">
<INPUT NAME=double_click TYPE=hidden>
<INPUT NAME=course_id TYPE=hidden VALUE="1">
<INPUT NAME=unique_id TYPE=hidden VALUE="230695">
<INPUT NAME=d_date TYPE=hidden VALUE="2012-09-07">
<INPUT NAME=Booking_Operation TYPE=hidden VALUE="Book Casual">
<INPUT NAME=SubmitButton TYPE=submit VALUE="Book Now">
</form>
</td>
</tr>
<tr>
最多可以有 40 个这样的 block 。 <td class=t_h>07:32</td>
是用户指定的时间。我需要自动按下与该时间相关的按钮。怎么办?
提前谢谢大家!
最佳答案
这就是 jQuery 的问题。自成一体。基本思想是查找带有文本 07:32
的类 t_h
元素。然后,在其父节点中,找到一个 form
元素并 submit()
它。
给你:
function submitFormForTime(time){
$(".t_h").each(function(i, obj){ // find each element with the class t_h
if ($(this).text() != time) return; // not the right one
$(this).parent().find("form").each(function(i, obj){
obj.submit(); // submit that form
});
});
}
submitFormForTime("07:32");
将此脚本添加到网站。要从 Objective-C 调用此脚本,请参阅:
从上述文档中,以下内容将从 Objective-C 调用 JavaScript 函数:
id win = [webView yourWebView]; // assumes your webView is called yourWebView
[win evaluateWebScript:@"submitFormForTime('07:32');"];
关于javascript - 从 Mac Cocoa 应用程序内提交 HTML 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12202633/