我正在尝试使用phantomJS(这是一个很棒的工具btw!)为我有登录凭据的页面提交表单,然后将目标页面的内容输出到stdout.我能够使用幻像访问表单并成功设置其值,但我不太确定提交表单和输出后续页面内容的正确语法.到目前为止我所拥有的是:
var page = new WebPage();
var url = phantom.args[0];
page.open(url, function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
console.log(page.evaluate(function () {
var arr = document.getElementsByClassName("login-form");
var i;
for (i=0; i < arr.length; i++) {
if (arr[i].getAttribute('method') == "POST") {
arr[i].elements["email"].value="mylogin@somedomain.com";
arr[i].elements["password"].value="mypassword";
// This part doesn't seem to work. It returns the content
// of the current page, not the content of the page after
// the submit has been executed. Am I …Run Code Online (Sandbox Code Playgroud) 我正在使用Bootstrap作为我的JSP页面.
我想使用<fieldset>和<legend>我的形式.这是我的代码.
<fieldset class="scheduler-border">
<legend class="scheduler-border">Start Time</legend>
<div class="control-group">
<label class="control-label input-label" for="startTime">Start :</label>
<div class="controls bootstrap-timepicker">
<input type="text" class="datetime" id="startTime" name="startTime" placeholder="Start Time" />
<i class="icon-time"></i>
</div>
</div>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
CSS是
fieldset.scheduler-border {
border: 1px groove #ddd !important;
padding: 0 1.4em 1.4em 1.4em !important;
margin: 0 0 1.5em 0 !important;
-webkit-box-shadow: 0px 0px 0px 0px #000;
box-shadow: 0px 0px 0px 0px #000;
}
legend.scheduler-border {
font-size: 1.2em !important;
font-weight: bold !important;
text-align: left !important; …Run Code Online (Sandbox Code Playgroud) 我有一个带两个按钮的页面.一个是<button>元素,另一个是元素<input type="submit">.按钮按顺序显示在页面上.如果我在表单中的任何位置的文本字段中按下<Enter>,click则会触发按钮元素的事件.我认为那是因为按钮元素位于第一位.
我找不到任何看起来像设置默认按钮的可靠方法,也不一定要在这一点上.在没有任何更好的情况下,我在表格的任何地方捕获了一个按键,如果它<Enter>是按下的键,我只是否定它:
$('form').keypress( function( e ) {
var code = e.keyCode || e.which;
if( code === 13 ) {
e.preventDefault();
return false;
}
})
Run Code Online (Sandbox Code Playgroud)
据我所知,到目前为止,它似乎正在起作用,但它感觉非常火腿.
有谁知道这样做的更复杂的技术?
同样,这个解决方案是否有任何陷阱,我只是不知道?
谢谢.
如何阻止表单使用jquery提交?
我尝试了一切 - 看到我在下面尝试过的3个不同的选项,但这一切都行不通:
$(document).ready(function() {
//option A
$("#form").submit(function(e){
e.preventDefault();
});
//option B
$("#form").submit(function(e){
stopEvent(e);
});
//option C
$("#form").submit(function(){
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?
更新 - 这是我的HTML:
<form id="form" class="form" action="page2.php" method="post">
<!-- tags in the form -->
<p class="class2">
<input type="submit" value="Okay!" />
</p>
</form>
Run Code Online (Sandbox Code Playgroud)
这里有什么不对吗?
有没有办法通过只告诉jquery/javascript中的父div名称来禁用表单中的所有字段(textarea/textfield/option/input/checkbox/submit等)?
HTML中没有办法使用三态检查按钮(是,否,为null),对吧?
是否有任何简单的技巧或解决方法,而不必自己呈现整个事物?
我正在尝试根据下拉菜单中的选定值更改表单操作.
基本上,HTML看起来像这样:
<form class="search-form" id="search-form" method="post" accept-charset="UTF-8" action="/search/user">
<select id="selectsearch" class="form-select" name="selectsearch">
<option value="people">Search people</option>
<option value="node">Search content</option>
</select>
<label>Enter your keywords: </label>
<input type="text" class="form-text" value="" size="40" id="edit-keys" name="keys" maxlength="255" />
<input type="submit" class="form-submit" value="Search" id="edit-submit" name="search"/>
</form>
Run Code Online (Sandbox Code Playgroud)
如果选择"人员"(默认情况下),则操作应为"/ search/user",如果选择了内容,则操作应为"/ search/content"
我还在四处寻找,但一直无法找到如何做到这一点.
我有1个表单,里面有多个复选框(每个都有代码):
<input type="checkbox" name="check_list" value="<? echo $row['Report ID'] ?>">
Run Code Online (Sandbox Code Playgroud)
$row['Report ID']数据库中的主键在哪里 - 每个值都不同.
我怎样才能知道检查了哪些复选框?(也许是多个)
这是一个收件箱系统,我有一个按钮,我想要(点击时)删除所有$row['Report ID']选中复选框的消息(ID:).
我想在铁轨上做这样的事情
以下是我目前在rails中的内容:
<%= form_for @order do |f| %>
<%= f.hidden_field :service, "test" %>
<%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但后来我得到了这个错误:
undefined method `merge' for "test":String
Run Code Online (Sandbox Code Playgroud)
如何在rails中的hidden_field中传递值?