【问题标题】:Javascript Web Crawler Confirm Confirmation boxJavascript 网络爬虫确认确认框
【发布时间】:2018-02-04 22:16:40
【问题描述】:

我正在尝试为学校项目确认 Javascript 中的确认框。出现确认框询问您是否要提交,我想以编程方式提交。这是表单的 HTML:

<form action="https://weekend.lps.wels.net/lpswp/index.php" method="post" id="form_wp_entry" onsubmit="return lpswp_confirm_submission('3,4','Friday,Saturday','Sunday')" style="display: inline;">
                        <table class="em_table" width="100%" style="margin-bottom: 5px;">

                            <tbody><tr>
                                <th align="left" id="lpswp_night_label_title_3">
                                    Friday
                                </th>
                            </tr>
                            <tr>
                                <td>

                                    Location: <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_dorm_3" value="dorm" checked="checked" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_dorm_3">Dorm</label> |
                                    <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_home_3" value="home" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_home_3">Home</label><br>
                                    <input type="radio" name="lpswp_nights[3][location]" id="lpswp_nights_location_other_3" value="other" onclick="lpswp_toggle_location(3)"> <label for="lpswp_nights_location_other_3" id="lpswp_night_label_text_3">Other</label>: 
                                    <input type="text" size="60" name="lpswp_nights[3][other]" id="lpswp_nights_other_3"><br>
                                    Phone Number (if known): <input type="text" size="20" name="lpswp_nights[3][phone]" id="lpswp_nights_phone_3"> (999-999-9999)
                                </td>
                            </tr>

                            <tr>
                                <th align="left" id="lpswp_night_label_title_4">
                                    Saturday
                                </th>
                            </tr>
                            <tr>
                                <td>
                                    <input type="checkbox" name="lpswp_nights[4][same]" id="lpswp_nights_same_4" value="1" checked="checked" onclick="lpswp_toggle_same(4)"> <label for="lpswp_nights_same_%temp_night%">Same as Friday night.</label><br>
                                    Location: <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_dorm_4" value="dorm" checked="checked" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_dorm_4">Dorm</label> |
                                    <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_home_4" value="home" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_home_4">Home</label><br>
                                    <input disabled="disabled" type="radio" name="lpswp_nights[4][location]" id="lpswp_nights_location_other_4" value="other" onclick="lpswp_toggle_location(4)"> <label for="lpswp_nights_location_other_4" id="lpswp_night_label_text_4">Other</label>: 
                                    <input disabled="disabled" type="text" size="60" name="lpswp_nights[4][other]" id="lpswp_nights_other_4"><br>
                                    Phone Number (if known): <input disabled="disabled" type="text" size="20" name="lpswp_nights[4][phone]" id="lpswp_nights_phone_4"> (999-999-9999)
                                </td>
                            </tr>

                            <tr>
                                <th align="left" id="lpswp_final_dinner_label_title">
                                    Sunday Dinner
                                </th>
                            </tr>
                            <tr>
                                <td id="lpswp_final_dinner_label_text" style="border: 0px;">
                                    I WILL be eating in the cafeteria: <input type="radio" name="lpswp_final_dinner" id="lpswp_final_dinner_1" value="1"><br>
                                    I will NOT be eating in the cafeteria: <input type="radio" name="lpswp_final_dinner" id="lpswp_final_dinner_0" value="0"><br>
                                    <input type="hidden" name="lpswp_final_dinner_night" value="5">
                                </td>
                            </tr>
                        </tbody></table>
                    <input type="submit" value="Submit Weekend Plans">
                    <!--input type="reset" value="Cancel" /-->
                    </form>

这是我当前对确认框没有任何作用的代码:

mWebView.loadUrl("javascript:(function(){" +
                            "document.getElementById('form_wp_entry').setAttribute('onsubmit','return true;');" +
                            ";})()");

请帮助我,我是 javascript 的新手...和一般的编码。

【问题讨论】:

    标签: javascript jquery html web-crawler


    【解决方案1】:

    您正在寻找 .submit()
    请注意,这不会触发与表单的 onsubmit 关联的任何功能:

    function output() {
      console.log('Submitted');
      return false;
    }
    
    // Forcibly submit the form
    function customSubmit() {
      document.getElementsByTagName('form')[0].submit();
    }
    <form name="a_form" onsubmit="return output()">
      <button type="submit">Submit</button>
    </form>
    <br />
    <button onclick="customSubmit()">Submit Programmatically</button>

    希望这会有所帮助!

    【讨论】:

    • 我认为你不明白我的问题。我正在尝试在 java 中使用 JavaScript 确认确认框。我正在制作一个网络爬虫应用程序。我无法更改 HTML。
    • 您不必更改 HTML -- .submit() 是一个 JavaScript 函数,document.getElementsByTagName('form')[0].submit() 将始终提交页面上的第一个表单,无论其 HTML 结构如何。你可以使用mWebView.loadUrl("javascript:document.getElementsByTagName('form')[0].submit();")之类的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多